ISO C++禁止声明没有自动迭代器类型的“it”
ISO C++ forbids declaration of ‘it’ with no type for auto iterator?
我有这六行:
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
它们在 VS2012 中编译得很好,但在 centOS6 上的 GCC 中,我收到以下错误:
./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定义如下:
struct CallbackAMX
{
bool PublicFound;
int POINTER;
CallbackAMX()
{
PublicFound = false;
POINTER = 0;
}
};
struct Callbacks
{
CallbackAMX ClosestNodeIDChange;
CallbackAMX GPSRouteCalculated;
};
std::map <AMX*, Callbacks> rcp_amxinfo;
如何在 Linux 上解决这些错误?
构建时启用 C++11 模式。为此,您可以在编译器标志中添加-std=gnu++11
(获取默认情况下打开的 GCC 扩展)或-std=c++11
(仅适用于 ISO C++)。
auto
在 C++11(推断类型)中的含义与在以前的标准(指定自动存储类)中的含义不同。
相关文章:
- 如何在c++迭代器类型中包装std::chrono
- 定义模板参数的迭代器类型
- C++如何乘以包含 std::variant 元素的向量的迭代器?正在执行迭代器类型的转换?
- 专门C++使用指针值类型的通用迭代器的模板函数?
- C++类字符串类型的迭代器
- 类型不可知的抽象以使用相同的运行时接口处理正向和反向迭代器和范围?
- 如何转换不同类型的迭代器
- 如何从迭代器中找到对的类型
- C++不兼容的迭代器类型
- 如何确定迭代器在 c++ 模板函数中指向的对象的类型?
- 迭代器的模板参数:函数在调用时推断类型?
- 如何推导 std::高级迭代器类型?
- 在 stl 容器包装器中定义迭代器类型
- 从迭代器转换为变量的类型.(C++11 模板)
- 使用迭代器成员函数是否仅适用于某些向量类型"empty()"?
- 如何编写使用迭代器和特定类型的模板化函数
- 从不同类型的容器的迭代器初始化向量
- 对矢量<类型*>迭代器感到困惑
- C++异构类型迭代器的迭代器
- 为什么c++标准需要std::分区来满足不同类型迭代器的不同复杂性