Map und kleiner Operator



  • Hallo,

    ich habe einen Map Container

    std::map<Location, Node> nodes;
    

    Location und Node sind jeweils eine Klasse.

    Allerdings erhalte ich Kompilerfehler

    Graph.cpp
    c:\programme\microsoft visual studio 8\vc\include\functional(143) : error C2678: Binärer Operator '<': Es konnte kein Operator gefunden werden, der einen linksseitigen Operanden vom Typ 'const Location' akzeptiert (oder keine geeignete Konvertierung möglich)
            c:\dokumente und einstellungen\florian\eigene dateien\visual studio 2005\projects\futurecar_1\location.h(13): kann 'bool Location::operator <(const Location &)' sein
            bei Anpassung der Argumentliste '(const Location, const Location)'
            c:\programme\microsoft visual studio 8\vc\include\functional(142): Bei der Kompilierung der  Klassen-template der bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const-Memberfunktion
            with
            [
                _Ty=Location
            ]
            c:\programme\microsoft visual studio 8\vc\include\map(72): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::less<_Ty>".
            with
            [
                _Ty=Location
            ]
            c:\programme\microsoft visual studio 8\vc\include\xtree(26): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>".
            with
            [
                _Kty=Location,
                _Ty=Node,
                _Pr=std::less<Location>,
                _Alloc=std::allocator<std::pair<const Location,Node>>,
                _Mfl=false
            ]
            c:\programme\microsoft visual studio 8\vc\include\xtree(68): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::_Tree_nod<_Traits>".
            with
            [
                _Traits=std::_Tmap_traits<Location,Node,std::less<Location>,std::allocator<std::pair<const Location,Node>>,false>
            ]
            c:\programme\microsoft visual studio 8\vc\include\xtree(94): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::_Tree_ptr<_Traits>".
            with
            [
                _Traits=std::_Tmap_traits<Location,Node,std::less<Location>,std::allocator<std::pair<const Location,Node>>,false>
            ]
            c:\programme\microsoft visual studio 8\vc\include\xtree(112): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::_Tree_val<_Traits>".
            with
            [
                _Traits=std::_Tmap_traits<Location,Node,std::less<Location>,std::allocator<std::pair<const Location,Node>>,false>
            ]
            c:\programme\microsoft visual studio 8\vc\include\map(82): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::_Tree<_Traits>".
            with
            [
                _Traits=std::_Tmap_traits<Location,Node,std::less<Location>,std::allocator<std::pair<const Location,Node>>,false>
            ]
            c:\dokumente und einstellungen\florian\eigene dateien\visual studio 2005\projects\futurecar_1\graph.h(10): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::map<_Kty,_Ty>".
            with
            [
                _Kty=Location,
                _Ty=Node
            ]
    

    Ich gehe davon aus, dass es irgendwas damit zu tun hat, dass die operator< Überladung in meiner Location Klasse nicht so wirklich funktioniert für den Sortieralgorithmus std::less

    bool Location::operator<(const Location& loc) 
    { 
      return (this->xAxis < loc.xAxis && this->yAxis < loc.yAxis) ;  
    }
    

    Was ist da genau los?

    LG



  • bool Location::operator<(const Location& loc) const
    {
      return (this->xAxis < loc.xAxis && this->yAxis < loc.yAxis) ;  
    }
    

    const-corectness



  • ohman ohman danke 🙂


Anmelden zum Antworten