2017-08-15 374 views
-2

我使用VS2008在Windows 10 我有这个功能的问题,希望你能帮助我使用`auto`产生错误C4430:缺少类型说明符 - 假定为int。注意:C++不支持默认int

void CPythonNetworkStream::AppearShopSign(DWORD dwVID, std::string stSign) { 
    if (stSign.empty()) 
     for (auto it = m_mapShopSign.begin(); it != m_mapShopSign.end(); ++it) 
      if (dwVID == it->first) 
       stSign = it->second; 

    // LogBoxf("AppearShopSign: %u-%s", dwVID, stSign.c_str()); 
    PyCallClassMemberFunc(m_apoPhaseWnd[PHASE_WINDOW_GAME], "BINARY_PrivateShop_Appear", Py_BuildValue("(is)", dwVID, stSign.c_str())); 
} 

错误消息

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
error C2440: 'initializing' : cannot convert from 'std::_Tree<_Traits>::iterator' to 'int' 
error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'int' (or there is no acceptable conversion) 
error C2227: left of '->first' must point to class/struct/union/generic type 
+4

VS 2008不支持'auto'类型说明符。 – LogicStuff

+2

'auto it'不支持VC++ 2008.您需要升级到其中一个最新版本。 –

+2

@LogicStuff它可能确实支持'auto'的原始C含义,但这不是OP所尝试使用的。 –

回答

1

auto关键字自C++ 11标准支持,而visual-studio 2008不支持该标准。

修复使用明确类型:

for (std::map<DWORD,std::string>::iterator it = m_mapShopSign.begin(); 
    // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
    it != m_mapShopSign.end(); 
    ++it) 
+0

应该是'const DWORD' – Viktor

+0

http://rextester.com/live/YSHPBV66254 – Viktor

+0

@Viktor你是否有任何证据表明地图已经被实例化为'std :: map 'from the给定的代码?你的regextester例子没有什么区别,推导出这样的'iterator'成员类型是很好的。 – user0042

0

如前所述auto是在C++ 11中为automatic type deduction引入的。在C++ 11之前,它被用来声明一个具有自动存储持续时间的局部变量。

+0

我不是100%确定的,但我相信你的后一段只适用于C标准。 – user0042

相关问题