ISO C++ forbids declaration of ‘it’ with no type for auto iterator?

auto, c++, compiler-errors, iterator

Solution

Enable C++11 mode when building. You do that by adding `-std=gnu++11` (to also get GCC extensions, which are on by default), or `-std=c++11` (for only ISO C++) to your compiler flags.

`auto` means something different in C++11 (where it deduces the type) than it does in the previous standard (where it specifies automatic storage class.)

Problem

I have these six lines: ``` auto it = rcp_amxinfo.find(LocalPass.script);//175 if (it != rcp_amxinfo.end()) //176 {//177 if(it->second.GPSRouteCalculated.PublicFound)//178 { ... amx_Exec(LocalPass.script, NULL, it->second.GPSRouteCalculated.POINTER);//186 ``` they compile perfectly fine in VS2012, but in GCC on centOS6 I get these errors: ``` ./RouteConnector/main.cpp:175: error: ISO C++ forbids declaration of ‘it’ with no type ./RouteConnector/main.cpp:175: error: cannot convert ‘std::_Rb_tree_iterator<std::pair<AMX* const, Callbacks> >’ to ‘int’ in initialization ./RouteConnector/main.cpp:176: error: no match for ‘operator!=’ in ‘it != rcp_amxinfo.std::map<_Key, _Tp, _Compare, _Alloc>::end [with _Key = AMX*, _Tp = Callbacks, _Compare = std::less<AMX*>, _Alloc = std::allocator<std::pair<AMX* const, Callbacks> >]()’ ./RouteConnector/main.cpp:178: error: base operand of ‘->’ is not a pointer ./RouteConnector/main.cpp:186: error: base operand of ‘->’ is not a pointer ``` rcp_amxinfo is defined as follow: ``` struct CallbackAMX { bool PublicFound; int POINTER; CallbackAMX() { PublicFound = false; POINTER = 0; } }; struct Callbacks { CallbackAMX ClosestNodeIDChange; CallbackAMX GPSRouteCalculated; }; std::map <AMX*, Callbacks> rcp_amxinfo; ``` How can I solv these errors on linux?

Original source