Konstante Liste durchgehen?



  • Hallo Forum,

    ich habe eine Funktion die eine konstante Liste zurück gibt. Wie kann ich nun die Liste durchgehen?
    Ich habe diese Beispiel aus der hiesiegen Container FAQ abgewandelte:

    const list<wstring>* oList = oMain->GetList();
    for (list<wstring>::iterator iter = oList->begin();
    	iter!=oList->end(); 
    	++iter) {
    	cout << *iter << endl;
    }
    

    Die Fehlermeldung ist:

    error C2440: 'initializing' : cannot convert from 'class std::list<class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> >,class std::allocator<class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > > >::const_iterator' to 'class std::list<class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> >,class std::allocator<class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > > >::iterator'
    No constructor could take the source type, or constructor overload resolution was ambiguous
    error C2678: binary '!=' : no operator defined which takes a left-hand operand of type 'class std::list<class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned sho
    rt> >,class std::allocator<class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > > >::iterator' (or there is no acceptable conversion)
    error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> >' (or there is no acceptable conversion)

    Könntet Ihr mir einen Tip geben was ich falsch mache?



  • ...

    for (list<wstring>::const_iterator
    

    ??

    Steht da eigentlich auch in der Fehlermeldung:

    Jakata schrieb:

    error C2440: 'initializing' : cannot convert from '... ::const_iterator' to '...::iterator'

    😃
    Ist aber "normal", dass man das nicht sieht. Ist eigentlich eher eine der Fehlermeldungen der Art "Wenn ich die Lösung schon habe, verstehe ich auch den Hinweis". 🤡

    Gruß,

    Simon2.



  • Vielen Dank 🙂

    Für einen Anfänger ist das nicht so leicht...



  • Jakata schrieb:

    Vielen Dank 🙂

    Für einen Anfänger ist das nicht so leicht...

    Das stimmt !

    Viel Erfolg noch,

    Simon2.


Anmelden zum Antworten