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 是否缺少它?

4

1 回答 1

7

这是msvc 中的一个错误。不幸的是,它在他们的优先级列表中并不高。

于 2013-04-03T18:53:04.773 回答