stl problem: could not deduce template argument...



  • Ok, ich hab da ein kleines Problem. Naja es is t so groß das ich einfach nicht mehr weiter komme...
    Um mal vereinfach darzustellen was mein Prob is hab ich mal folgenden bsp. code gebastelt:

    #include <list>
    
    class MyType
    {
        MyType(){}
        ~MyType(){}
    };
    
    typedef std::list<MyType> tpLst;
    typedef tpLst::iterator tpLstIt;
    
    int main()
    {
        tpLst list;
        tpLstIt it = list.begin();
        it < list.end(); // hier liegt das Problem
        return 0;
    }
    

    Ich möchte eigentlich nur durch eine Liste von MyType's iterieren. Wenn ich den oben stehenden Code compilieren will bekomm ich allerdings folgende Fehler:

    cl.exe /nologo /GX /GR /DUNICODE /Ox /Og /DNDEBUG /GX  /ID:\Progs\arbeiten\vc++\include  /c main.cpp /Foobj\Release\main.obj
    main.cpp
    main.cpp(16) : error C2784: 'bool std::operator <(const std::list<_Ty,_Alloc> &,const std::list<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'tpLstIt'
            D:\Progs\arbeiten\vc++\include\list(991) : see declaration of 'std::operator`<''
    main.cpp(16) : error C2784: 'bool std::operator <(const std::list<_Ty,_Alloc> &,const std::list<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'tpLstIt'
            D:\Progs\arbeiten\vc++\include\list(991) : see declaration of 'std::operator`<''
    main.cpp(16) : error C2784: 'bool std::operator <(const std::list<_Ty,_Alloc> &,const std::list<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'tpLstIt'
            D:\Progs\arbeiten\vc++\include\list(991) : see declaration of 'std::operator`<''
    main.cpp(16) : error C2784: 'bool std::operator <(const std::list<_Ty,_Alloc> &,const std::list<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'tpLstIt'
            D:\Progs\arbeiten\vc++\include\list(991) : see declaration of 'std::operator`<''
    main.cpp(16) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'tpLstIt'
            D:\Progs\arbeiten\vc++\include\xutility(655) : see declaration of 'std::operator`<''
    main.cpp(16) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'tpLstIt'
            D:\Progs\arbeiten\vc++\include\xutility(655) : see declaration of 'std::operator`<''
    main.cpp(16) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'tpLstIt'
            D:\Progs\arbeiten\vc++\include\xutility(655) : see declaration of 'std::operator`<''
    main.cpp(16) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'tpLstIt'
            D:\Progs\arbeiten\vc++\include\xutility(655) : see declaration of 'std::operator`<''
    main.cpp(16) : 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 'tpLstIt'
            D:\Progs\arbeiten\vc++\include\utility(73) : see declaration of 'std::operator`<''
    main.cpp(16) : 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 'tpLstIt'
            D:\Progs\arbeiten\vc++\include\utility(73) : see declaration of 'std::operator`<''
    main.cpp(16) : 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 'tpLstIt'
            D:\Progs\arbeiten\vc++\include\utility(73) : see declaration of 'std::operator`<''
    main.cpp(16) : 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 'tpLstIt'
            D:\Progs\arbeiten\vc++\include\utility(73) : see declaration of 'std::operator`<''
    main.cpp(16) : error C2676: binary '<' : 'tpLstIt' does not define this operator or a conversion to a type acceptable to the predefined operator
    

    Mit einem vector funktioniert es problemlos aber sollten die iteratoren nicht für alle datencontainer gleich funktionieren? Ich bin am verzweifeln!



  • Fürs iterieren brauchst du nur den != operator.

    mfg.



  • Um den op< nutzen zu können, benötigst du einen random-access-iterator. Die liste bietet aber nur den bidirectional-iterator an. und der besitzt halt nur op!=. Mit dem kannste aber genausogut iterieren 😉



  • ah, das macht natürlich sinn, hätt ich auch sellbst drauf kommen können...

    naja, vielen dank auf jeden fall!


Anmelden zum Antworten