gpt4 book ai didi

c++ - 匿名结构内部循环

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:30:01 26 4
gpt4 key购买 nike

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

最佳答案

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

关于c++ - 匿名结构内部循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15795532/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com