std::list bekannten typs sortieren

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • std::list bekannten typs sortieren

    Ich wollte eine Liste aus den unten angegebenen Structs sortieren.
    Leider erhalte ich das die ganz unten Zitierten Compiler-Fehler.
    Was mache ich falsch? / geht das vll auch einfacher?

    Quellcode

    1. #include <iostream>
    2. #include <list>
    3. #include <functional>
    4. struct ABC
    5. {
    6. int begin, end;
    7. };
    8. struct less_ABC
    9. : public binary_function<ABC, ABC, bool>
    10. {
    11. bool operator()(const ABC& x, const ABC& y) const {return x.begin < y.begin;}
    12. };
    13. int main()
    14. {
    15. std::list<ABC> myList;
    16. ABC dummy;
    17. dummy.begin = 5;
    18. dummy.end = 10;
    19. myList.push_back(dummy);
    20. dummy.begin = 10;
    21. dummy.end = 15;
    22. myList.push_back(dummy);
    23. dummy.begin = 15;
    24. dummy.end = 20;
    25. myList.push_back(dummy);
    26. myList.sort(less_ABC);
    27. }
    Alles anzeigen


    mingw32-make -f makefile all
    g++ -c main.cpp
    main.cpp:11: error: expected template-name before '<' token
    main.cpp:11: error: expected `{' before '<' token
    main.cpp:11: error: expected unqualified-id before '<' token
    main.cpp:11: error: expected `,' or `;' before '<' token
    main.cpp: In function `int main()':
    main.cpp:37: error: invalid use of undefined type `struct less_ABC'
    main.cpp:11: error: forward declaration of `struct less_ABC'
    mingw32-make: *** [main.o] Error 1
    There are only 10 types of people in the world: Those who understand binary, and those who don't.

    Download meines ersten Spiels:HIER
    Über Feedback würde ich mich freuen ;)
  • mit

    : public std::binary_function<ABC, ABC, bool>

    funktionierts :)
    warum das im Stroustrup-Buch verschwiegen wird, obwohl der immer wieder darauf besteht namespaces nicht durch using überflüssig zu machen ist mir allerdings nicht klar ...


    Eine Chance dass ich das auch VC6 klar machen kan?

    OK VC6 ist mal wieder zu dumm den Standart zu implementieren.
    Abhilfe schafft der STL-Port stlport.org/
    There are only 10 types of people in the world: Those who understand binary, and those who don't.

    Download meines ersten Spiels:HIER
    Über Feedback würde ich mich freuen ;)