2017-08-15 372 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

相關問題