Reputation: 81
I want to use reference in std::map
typedef const std::function<void(const cocos2d::Ref*)>& callBack;
std::map<const std::string&, callBack> m_mapListener
and my error message is:
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
How could I fix it?
Upvotes: 0
Views: 236
Reputation: 42899
Define your map
as:
std::map<std::string, callBack> m_mapListener;
STL containers don't support references because they require that their element type meets the requirements of Erasable, in which case references don't.
Upvotes: 3