矢量地图 - 如何做到这一点

时间:2016-04-30 19:11:17

标签: c++ dictionary vector stl

我有以下代码:

std::map<std::wstring, std::vector<Table> > my_map;
my_map[L"abc"].push_back( Table() );

但是尝试编译它会产生很多错误{MSVC 2010},我根本不理解。

所以,一个修辞问题:为什么MS会给出一堆人们无法理解的错误?第二:我如何修复第二行?

谢谢。

以下是参考的错误:

2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2784: 'bool std::operator <(const std::vector<_Ty,_Ax> &,const std::vector<_Ty,_Ax> &)' : could not deduce template argument for 'const std::vector<_Ty,_Ax> &' from 'const std::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\vector(1502) : see declaration of 'std::operator <'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(124) : while compiling class template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const'
2>          with
2>          [
2>              _Ty=std::wstring
2>          ]
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\map(71) : see reference to class template instantiation 'std::less<_Ty>' being compiled
2>          with
2>          [
2>              _Ty=std::wstring
2>          ]
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xtree(451) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled
2>          with
2>          [
2>              _Kty=std::wstring,
2>              _Ty=std::vector<Table>,
2>              _Pr=std::less<std::wstring>,
2>              _Alloc=std::allocator<std::pair<const std::wstring,std::vector<Table>>>,
2>              _Mfl=false
2>          ]
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xtree(520) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled
2>          with
2>          [
2>              _Traits=std::_Tmap_traits<std::wstring,std::vector<Table>,std::less<std::wstring>,std::allocator<std::pair<const std::wstring,std::vector<Table>>>,false>
2>          ]
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xtree(659) : see reference to class template instantiation 'std::_Tree_val<_Traits>' being compiled
2>          with
2>          [
2>              _Traits=std::_Tmap_traits<std::wstring,std::vector<Table>,std::less<std::wstring>,std::allocator<std::pair<const std::wstring,std::vector<Table>>>,false>
2>          ]
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\map(81) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled
2>          with
2>          [
2>              _Traits=std::_Tmap_traits<std::wstring,std::vector<Table>,std::less<std::wstring>,std::allocator<std::pair<const std::wstring,std::vector<Table>>>,false>
2>          ]
2>          C:\Users\Igor\OneDrive\Documents\dbhandler_app\dbinterface\database.h(115) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
2>          with
2>          [
2>              _Kty=std::wstring,
2>              _Ty=std::vector<Table>
2>          ]
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2784: 'bool std::operator <(const std::vector<_Ty,_Ax> &,const std::vector<_Ty,_Ax> &)' : could not deduce template argument for 'const std::vector<_Ty,_Ax> &' from 'const std::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\vector(1502) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2784: 'bool std::operator <(const std::vector<_Ty,_Ax> &,const std::vector<_Ty,_Ax> &)' : could not deduce template argument for 'const std::vector<_Ty,_Ax> &' from 'const std::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\vector(1502) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): 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::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xtree(1885) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): 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::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xtree(1885) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): 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::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xtree(1885) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'const std::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\memory(2582) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'const std::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\memory(2582) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'const std::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\memory(2582) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(1356) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(1356) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(1356) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const std::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(1179) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const std::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(1179) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const std::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(1179) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\utility(318) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\utility(318) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::wstring'
2>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\utility(318) : see declaration of 'std::operator <'
2>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2676: binary '<' : 'const std::wstring' does not define this operator or a conversion to a type acceptable to the predefined operator

1 个答案:

答案 0 :(得分:2)

划伤下巴嗯。此错误消息看起来很可疑:

  

2&gt; c:\ Program Files(x86)\ Microsoft Visual Studio   10.0 \ VC \ include \ xfunctional(125):错误C2676:二进制'&lt;' :'const std :: wstring'没有定义此运算符或转换为类型   预定义运算符

可接受

拉出重物并把它扔到桌子上我看到...进入我的水晶球... 超链接Using an std::string as a key for an std::map神秘地漂浮在雾中

啊,是的!就是这样。你忘记了#include <string>

当你:

时会发生这种情况
  1. 不要制作MCVE

  2. 忽视遵循之前评论者的建议“仔细检查您是否有#include <string>

相关问题