Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我在 clang 3.2 中编译它时
for(auto x : {1, 1.2}){}
我收到这样的错误:
错误:不能使用类型“void”作为范围
这是什么意思?
您在初始化列表中混合了您的类型。在这种情况下,它可以很清楚,但不要忘记
std::string foo; for(auto x : {foo, "bar"}){}
也是 2 种不同的类型。当然还有很多其他情况你可能希望它工作,但类型必须完全匹配。