2016-04-30 3 views
1

を行うにはどのように私は次のコードを持っている:マップ - それを

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

が、それをコンパイルしようとしているが、それは私が全く理解していないこれは、エラー{MSVC 2010}の多くを提供します。

したがって、修辞的な質問の1つ:なぜMSは人々が理解できないエラーの束を与えているのですか?そして2番目: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(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 
+2

'vector'と' map'をインクルードしましたか? – Rakete1111

+0

http://stackoverflow.com/help/mcve –

+2

マイクロソフトのコンパイラは、解読不可能なエラーメッセージの大量の髪の毛であなたを埋葬するためのすべての言い訳をする唯一のC++コンパイラではありません。 –

答えて

1

傷のあごフム。このエラーメッセージは疑わしい:

2> C:\プログラムファイルのMicrosoftのVisual Studio \(x86の) 10.0 \ VC \には、\ xfunctional(125):エラーC2676:バイナリ '<':「constのSTD: :wstringのは、」事前に定義されたオペレータに許容可能なこの演算子やタイプ への変換を定義していない

は重いものを引き出し、私の水晶玉の中に...テーブル私が見にそれをplops ... ハイフリンクUsing an std::string as a key for an std::mapは霧の中に不思議に浮かぶ

ああ!それはそれだった。あなたは#include <string>を忘れました。あなたと何が起こるかだ

  1. が前のコメント投稿者のアドバイスに従うことをMCVE

  2. ネグレクトを生成しないと、「あなたが持っている場合は、二重チェック#include <string>

+0

これは非常に奇妙です。 std :: wstringを使用する他のすべてのコードは、このインクルードなしで正常にコンパイルされます。しかし、はい - あなたは正しい。行方不明で、追加した後、コードがコンパイルされます。 – Igor