3

我有这六行:

    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 上解决这些错误?

4

1 回答 1

10

构建时启用 C++11 模式。您可以通过添加-std=gnu++11(也获得默认情况下启用的 GCC 扩展)或-std=c++11(仅适用于 ISO C++)到您的编译器标志来做到这一点。

auto在 C++11 中(它推断类型)中的含义与在之前的标准中(它指定自动存储类)中的含义不同。

于 2012-12-08T04:42:56.530 回答