什么是"错误:不能使用类型'void'作为范围"实际上是什么意思?

Nic*_*ick 11 c++ clang

当我在clang 3.2中编译它时

for(auto x : {1, 1.2}){}
Run Code Online (Sandbox Code Playgroud)

我收到这样的错误:

错误:不能使用'void'类型作为范围

这是什么意思?

Nic*_*ick 15

您在初始化列表中混合了类型.在这种情况下,它可以很清楚,但不要忘记

std::string foo;
for(auto x : {foo, "bar"}){}
Run Code Online (Sandbox Code Playgroud)

也是2种不同的类型.当然还有很多其他情况,你可能希望它能够工作,但类型必须完全匹配.