fixed: error C2784 from compiling adding an entry to a std::map

Got the above error, when compiling something that looked like this:

std::map<std::string, myType> myMap;
myMap[“Test”] = myType();

Looked around on the net, didn’t find the answer, thought about it for a bit and then realised I was missing #include <string> which fixed the problem. The error was a bit cryptic. Look for yourself at this dump from the compiler output:

1>C:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: ‘bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)’ : could not deduce template argument for ‘const std::_Tree<_Traits> &’ from ‘const std::string’

1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(1372) : see declaration of ‘std::operator <’
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\functional(142) : while compiling class template member function ‘bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const’
1>        with
1>        [
1>            _Ty=std::string
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\map(72) : see reference to class template instantiation ‘std::less<_Ty>’ being compiled
1>        with
1>        [
1>            _Ty=std::string
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(26) : see reference to class template instantiation ‘std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>’ being compiled
1>        with
1>        [
1>            _Kty=std::string,
1>            _Ty=std::string,
1>            _Pr=std::less<std::string>,
1>            _Alloc=std::allocator<std::pair<const std::string,std::string>>,
1>            _Mfl=false
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(68) : see reference to class template instantiation ‘std::_Tree_nod<_Traits>’ being compiled
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,std::string,std::less<std::string>,std::allocator<std::pair<const std::string,std::string>>,false>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(94) : see reference to class template instantiation ‘std::_Tree_ptr<_Traits>’ being compiled
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,std::string,std::less<std::string>,std::allocator<std::pair<const std::string,std::string>>,false>
1>        ]

http://johnstewien.wordpress.com/2009/12/02/fixed-error-c2784-from-compiling-adding-an-entry-to-a-stdmap/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值