使用`auto`产生错误C4430:缺少类型说明符 - 假定为int。注意:C++不支持默认int
问题描述:
我使用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
答
的auto
关键字自C++ 11标准支持,而visual-studio 2008不支持该标准。
修复使用明确类型:
for (std::map<DWORD,std::string>::iterator it = m_mapShopSign.begin();
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
it != m_mapShopSign.end();
++it)
答
如前所述auto
是在C++ 11中为automatic type deduction引入的。在C++ 11之前,它被用来声明一个具有自动存储持续时间的局部变量。
+0
我不是100%确定的,但我相信你的后一段只适用于C标准。 – user0042
VS 2008不支持'auto'类型说明符。 – LogicStuff
'auto it'不支持VC++ 2008.您需要升级到其中一个最新版本。 –
@LogicStuff它可能确实支持'auto'的原始C含义,但这不是OP所尝试使用的。 –