2016-01-22 114 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