STL: map<string,void*> macht Probleme
-
Möchte für ein aktuelles Projekt einen Ressourcenmanager implementieren, der Pointer auf geladene Objekte in einer Map speichert und den Zugriff über den Dateinamen erlaubt.
Ansatz: eine map<string,void*>.
Dabei tauchen jedoch überraschenderweise Probleme auf; folgender simpler Beispielcode liefert schon Fehler:#include <map> #include <cstring> using namespace std; int main( int argc, char **argv ) { map<string, string> bla; bla["hallo"] = "hello"; bla.find("hallo"); return 0; }Ich benutze VC++ 2008 unter Vista 32bit.
Was ist da los?exaktes Error-Log:
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)": template-Argument für "const std::_Tree<_Traits> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\xtree(1466): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(142): Bei der Kompilierung der Klassen-template der bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const-Memberfunktion
with
[
_Ty=std::string
]
e:\programme\visual studio 2008\vc\include\map(68): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::less<_Ty>".
with
[
_Ty=std::string
]
e:\programme\visual studio 2008\vc\include\xtree(22): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>".
with
[
_Kty=std::string,
_Ty=std::string,
_Pr=std::lessstd::string,
_Alloc=std::allocator<std::pair<const std::string,std::string>>,
_Mfl=false
]
e:\programme\visual studio 2008\vc\include\xtree(63): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::_Tree_nod<_Traits>".
with
[
_Traits=std::_Tmap_traits<std::string,std::string,std::lessstd::string,std::allocator<std::pair<const std::string,std::string>>,false>
]
e:\programme\visual studio 2008\vc\include\xtree(89): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::_Tree_ptr<_Traits>".
with
[
_Traits=std::_Tmap_traits<std::string,std::string,std::lessstd::string,std::allocator<std::pair<const std::string,std::string>>,false>
]
e:\programme\visual studio 2008\vc\include\xtree(107): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::_Tree_val<_Traits>".
with
[
_Traits=std::_Tmap_traits<std::string,std::string,std::lessstd::string,std::allocator<std::pair<const std::string,std::string>>,false>
]
e:\programme\visual studio 2008\vc\include\map(78): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::_Tree<_Traits>".
with
[
_Traits=std::_Tmap_traits<std::string,std::string,std::lessstd::string,std::allocator<std::pair<const std::string,std::string>>,false>
]
d:\daten\coding\smile_sdl\source\main.cpp(11): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::map<_Kty,_Ty>".
with
[
_Kty=std::string,
_Ty=std::string
]
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)": template-Argument für "const std::_Tree<_Traits> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\xtree(1466): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)": template-Argument für "const std::_Tree<_Traits> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\xtree(1466): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)": template-Argument für "const std::_Tree<_Traits> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\xtree(1466): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)": template-Argument für "const std::reverse_iterator<_RanIt> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\xutility(2236): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)": template-Argument für "const std::reverse_iterator<_RanIt> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\xutility(2236): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)": template-Argument für "const std::reverse_iterator<_RanIt> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\xutility(2236): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)": template-Argument für "const std::reverse_iterator<_RanIt> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\xutility(2236): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)": template-Argument für "const std::_Revranit<_RanIt,_Base> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\xutility(2046): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)": template-Argument für "const std::_Revranit<_RanIt,_Base> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\xutility(2046): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)": template-Argument für "const std::_Revranit<_RanIt,_Base> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\xutility(2046): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)": template-Argument für "const std::_Revranit<_RanIt,_Base> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\xutility(2046): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)": template-Argument für "const std::pair<_Ty1,_Ty2> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\utility(84): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)": template-Argument für "const std::pair<_Ty1,_Ty2> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\utility(84): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)": template-Argument für "const std::pair<_Ty1,_Ty2> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\utility(84): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(143) : error C2784: "bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)": template-Argument für "const std::pair<_Ty1,_Ty2> &" konnte nicht von "const std::string" hergeleitet werden.
e:\programme\visual studio 2008\vc\include\utility(84): Siehe Deklaration von 'std::operator <'
e:\programme\visual studio 2008\vc\include\functional(143) : error C2676: Binärer Operator '<': 'const std::string' definiert diesen Operator oder eine Konvertierung in einen für den vordefinierten Operator geeigneten Typ nicht
-
Schon mal #include <string> anstatt #include <cstring> probiert. Desweiteren Resourcen mit void* managen zu wollen, ist eher ungeschickt.
-
Wow, das scheint wirklich am Header zu liegen. mit <string> funktioniert es.
Danke für die schnelle Hilfe!
Ich dachte eigentlich <cstring> wäre der aktuelle Header den man benutzen sollte? Muss aber auch zugeben dass ich die STL bisher eher gemieden habe.void* war übrigens nur Schreibfaulheit, tatsächlich handelt es sich momentan um SDL_Surface*

-
hasu schrieb:
...
Ich dachte eigentlich <cstring> wäre der aktuelle Header den man benutzen sollte? ...Nicht verwechseln:
- "string.h" (C-String-Funktionen wie strcpy, ...) wurde in C++ zu "cstring"
- in "string" ist in C++ die Klasse std::string (&Co) deklariertGruß,
Simon2.