内环

2013-04-03 23 views
4

匿名结构下面的代码编译罚款与G ++内环

#include <iostream> 
using namespace std; 

int main() 
{ 
    for (struct { int i; double j; } x = {0,0}; x.i < 10; ++x.i, x.j+=.1) 
    { 
     std::cout << x.i << " " << x.j << '\n'; 
    } 
} 

但随着MSVC2005我得到的错误

error C2332: 'struct' : missing tag name 
error C2143: syntax error : missing ')' before '{' 
warning C4094: untagged 'struct' declared no symbols 
error C2059: syntax error : 'empty declaration' 
error C2143: syntax error : missing ';' before ')' 
error C2143: syntax error : missing ';' before ')' 
error C2065: 'x' : undeclared identifier 
error C2059: syntax error : '{' 
error C2143: syntax error : missing ';' before '{' 
error C2143: syntax error : missing ';' before '}' 
error C2228: left of '.i' must have class/struct/union 
1>  type is ''unknown-type'' 
error C2228: left of '.i' must have class/struct/union 
1>  type is ''unknown-type'' 
error C2228: left of '.j' must have class/struct/union 
1>  type is ''unknown-type'' 
error C2059: syntax error : ')' 
error C2143: syntax error : missing ';' before '{' 
error C2228: left of '.i' must have class/struct/union 
1>  type is ''unknown-type'' 
error C2228: left of '.j' must have class/struct/union 
1>  type is ''unknown-type'' 

我想知道,如果匿名结构内循环是一种“延伸”或语言功能和MSC2005是否缺少它?

+2

我很确定它是标准的。铿锵声++用“-pedantic-errors”接受它。 – 2013-04-03 18:50:29

+1

为什么你想要做这样的事情开始?! – 2013-04-03 18:50:34

+1

仍然[不能在VS2012上编译](http://rise4fun.com/Vcpp/WMz)。可能是海湾合作委员会的扩展 - 我不确定。 – Synxis 2013-04-03 18:50:36

回答

7

这是一个bug in msvc。不幸的是,它们的优先级列表并不高。

+4

'关闭不会修复':O – 2013-04-03 18:55:46

+3

@stardust_:I [再次报告](https://connect.microsoft.com/VisualStudio/feedback/details/782926/class-declaration-fails-in-for-循环)。 – 2013-04-03 19:17:05