Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "error: cannot use type 'void' as a range" actually mean?

Tags:

c++

clang

When I compile this in clang 3.2

for(auto x : {1, 1.2}){}

I get an error like this:

error: cannot use type 'void' as a range

What does it mean?

like image 588
Nick Avatar asked May 09 '13 13:05

Nick


1 Answers

You mixed your types in the initializer list. In this case it can be pretty clear, but don't forget

std::string foo;
for(auto x : {foo, "bar"}){}

Are also 2 separate types. There are of course plenty of other cases where you may expect it to work, but the types have to match exactly.

like image 195
Nick Avatar answered Sep 23 '22 07:09

Nick