内部循环中的匿名结构

时间:2013-04-03 18:47:50

标签: c++ gcc g++

下面的代码用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是否缺少它?

1 个答案:

答案 0 :(得分:7)

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