You are not logged in.

  • Login

1

Saturday, February 10th 2007, 12:50pm

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?

C Quellcode

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

Quoted


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

2

Saturday, February 10th 2007, 2:26pm

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 http://www.stlport.org/

Similar threads

Social bookmarks