string, map STL problem
-
Netmeisters, I am trying to do something which should be simple. Using Visual C++ I want to create a map containing an STL string as a key and my own type as a value. #include #include #include using namespace std; mapslips; Then to add a pair to the map: string str; pair::iterator, bool> ret = slips.insert(map::value_type(str,report)); But this produces a host of error messages that I've included below. Can't figure these out at all. When I comment out the pair &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string' c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(138) : while compiling class-template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const std::string &) const' with [ _Ty=std::string ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\map(36) : see reference to class template instantiation 'std::less<_Ty>' being compiled with [ _Ty=std::string ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(19) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled with [ _Kty=std::string, _Ty=CReport, _Pr=std::less, _Alloc=std::allocator>, _Mfl=false ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(61) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled with [ _Traits=std::_Tmap_traits,std::allocator>,false> ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(83) : see reference to class template instantiation 'std::_Tree_ptr<_Traits>' being compiled with [ _Traits=std::_Tmap_traits,std::allocator>,false> ] c:\
-
Netmeisters, I am trying to do something which should be simple. Using Visual C++ I want to create a map containing an STL string as a key and my own type as a value. #include #include #include using namespace std; mapslips; Then to add a pair to the map: string str; pair::iterator, bool> ret = slips.insert(map::value_type(str,report)); But this produces a host of error messages that I've included below. Can't figure these out at all. When I comment out the pair &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string' c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(138) : while compiling class-template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const std::string &) const' with [ _Ty=std::string ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\map(36) : see reference to class template instantiation 'std::less<_Ty>' being compiled with [ _Ty=std::string ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(19) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled with [ _Kty=std::string, _Ty=CReport, _Pr=std::less, _Alloc=std::allocator>, _Mfl=false ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(61) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled with [ _Traits=std::_Tmap_traits,std::allocator>,false> ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(83) : see reference to class template instantiation 'std::_Tree_ptr<_Traits>' being compiled with [ _Traits=std::_Tmap_traits,std::allocator>,false> ] c:\
It compiles fine for me, are you sure it's not some other thing that is causing the trouble? Maybe post some of the code surrounding this snippet. cheers, -B
-
Netmeisters, I am trying to do something which should be simple. Using Visual C++ I want to create a map containing an STL string as a key and my own type as a value. #include #include #include using namespace std; mapslips; Then to add a pair to the map: string str; pair::iterator, bool> ret = slips.insert(map::value_type(str,report)); But this produces a host of error messages that I've included below. Can't figure these out at all. When I comment out the pair &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string' c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(138) : while compiling class-template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const std::string &) const' with [ _Ty=std::string ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\map(36) : see reference to class template instantiation 'std::less<_Ty>' being compiled with [ _Ty=std::string ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(19) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled with [ _Kty=std::string, _Ty=CReport, _Pr=std::less, _Alloc=std::allocator>, _Mfl=false ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(61) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled with [ _Traits=std::_Tmap_traits,std::allocator>,false> ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(83) : see reference to class template instantiation 'std::_Tree_ptr<_Traits>' being compiled with [ _Traits=std::_Tmap_traits,std::allocator>,false> ] c:\
For extracting the essence out of these weired error-messages, you can try using STLError Decryptor[^] For me, it works fine - and it is free:)
My opinions may have changed, but not the fact that I am right.
-
Netmeisters, I am trying to do something which should be simple. Using Visual C++ I want to create a map containing an STL string as a key and my own type as a value. #include #include #include using namespace std; mapslips; Then to add a pair to the map: string str; pair::iterator, bool> ret = slips.insert(map::value_type(str,report)); But this produces a host of error messages that I've included below. Can't figure these out at all. When I comment out the pair &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string' c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(138) : while compiling class-template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const std::string &) const' with [ _Ty=std::string ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\map(36) : see reference to class template instantiation 'std::less<_Ty>' being compiled with [ _Ty=std::string ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(19) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled with [ _Kty=std::string, _Ty=CReport, _Pr=std::less, _Alloc=std::allocator>, _Mfl=false ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(61) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled with [ _Traits=std::_Tmap_traits,std::allocator>,false> ] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(83) : see reference to class template instantiation 'std::_Tree_ptr<_Traits>' being compiled with [ _Traits=std::_Tmap_traits,std::allocator>,false> ] c:\
You must make sure you have an #include <string> in your source file. Frequently you'll get things to compile with the declarations looking fine, but when usages start if the actual include isn't there then the compiler doesn't know what to do. I think this is being caused by the underlying compiler mechanics of how it instantiates templates.