2016-01-22 60 views
0

我想使用的std ::參考地圖使用參考::地圖

typedef const std::function<void(const cocos2d::Ref*)>& callBack; 

std::map<const std::string&, callBack> m_mapListener 

和我的錯誤信息是:

error C2535: 'const std::function<void (const cocos2d::Ref *)> &std::map<const std::string &,callBack, 
std::less<_Kty>,std::allocator<std::pair<_Kty,_Ty>>>::operator [](const std::basic_string 
<char,std::char_traits<char>,std::allocator<char>> &)' : 
member function already defined or declared 
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\map 

我怎麼能解決這個問題?

+5

這與'std :: function'無關。下一次執行一些實驗,例如拿掉'std :: function'並查看你的問題是否仍然存在(它的作用)。另外,在你的問題中提供正確的[testcases](http://stackoverflow.com/help/mcve):這裏你的錯誤信息抱怨'operator []',但是你實際上沒有使用'operator [] '。無論如何,我們都可以爲您解決問題。 –

回答

3

定義你的map爲:因爲他們需要自己的元素類型滿足可擦寫的要求,在這種情況下引用並不

std::map<std::string, callBack> m_mapListener; 

STL容器不支持引用。

+0

它適合我,謝謝 – rontgen