chaosfirebit
chaosfirebit

Reputation: 111

Error: does not name a type (using auto)

I am studying auto with the c++ primer 5th edition. They gave me examples such as:

auto item = val1 + val2;

From what I understand auto tells you what type forms from the expression you make. So I did my own:

int test1 = 69, test2 = 72;
auto test3 = test1 + test2;

but i got the error: " 'test3' does not name a type"

What does this mean? I though test3 will become the same type as test1,test2 which is int.

Upvotes: 0

Views: 8735

Answers (2)

user19489578
user19489578

Reputation:

if you using code blocks go to settings in the up bar click on compiler... then mark "Have g++ follow the C++11 ISO C++ language standard" option. else if U use another programme then you have to search how to activite c++11 option in the programme

Upvotes: 0

delta
delta

Reputation: 3818

I run the example without --std=c++11, it fails with the same error message.

Try to configure codeblocks again like this suggests.

Or you can run the code by hand like g++ --std=c++11 code.cc.

To see if C++11 is enabled, you can type more C++11 code, like just declaring nested vector vector<vector<int>> vv; to see if it deals >> well.


  1. How can I add C++11 support to Code::Blocks compiler?

Upvotes: 2

Related Questions