|
From: Ioannis V. <no...@ho...> - 2002-08-18 21:11:43
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Abhijit Shylanath
> Sent: Sunday, August 18, 2002 11:47 AM
> To: Dev-C++ Mailing List
> Subject: [Dev-C++] STL sort() problem
>
>
> Greets.
>
> I'm using a vector of a structure pointer (I use dynamic
> allocation), like
> so:
>
> vector<PlsLine *> lines;
>
> and PlsLine is a structure:
>
> typedef struct _PlsLine
> {
> char *fn; // Full filename (c:\foo\bar.mp3)
> char *filename; // Filename part only (bar.mp3)
> int size; // Filesize
> } PlsLine;
>
> I need to sort this, and I call sort() like this:
>
> sort(lines.begin(), lines.end());
>
> However, sort() uses the comparison operators (< and >), and
> I can't define
> them for pointers... The compiler flags this:
>
> bool operator <(const PlsLine *&left, const PlsLine *&right)
>
> as an error. It says it should be a class or enumerated type.
Yes you can not have a reference to a pointer with exception to
templates.
> I tried doing
> this:
>
> bool operator <(const PlsLine &left, const PlsLine &right)
>
> and the compile worked, but it doesn't seem to sort.
> Any work-around?
Yes, you probably made some logical error in the definition of
operator<(). Send us its definition.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|