匿名结构下面的代码编译罚款与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是否缺少它?
我很确定它是标准的。铿锵声++用“-pedantic-errors”接受它。 – 2013-04-03 18:50:29
为什么你想要做这样的事情开始?! – 2013-04-03 18:50:34
仍然[不能在VS2012上编译](http://rise4fun.com/Vcpp/WMz)。可能是海湾合作委员会的扩展 - 我不确定。 – Synxis 2013-04-03 18:50:36