Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list::sort() and overloading the less-than operator

Status
Not open for further replies.

biot023

Programmer
Nov 8, 2001
403
0
0
GB
Hi.
I need to sort a list containing a class I've called Tbau_feature. I have overloaded the less-than operator in the class definition, and it performs the comparison on a long value called Famendment_number with the following code:

virtual bool operator<(const Tbau_feature& rhs){
return Famendment_number<rhs.Famendment_number;}

The trouble is, I get this error when I try to compile:
E2093 'operator<' not implemented in type 'Tbau_feature' for arguments of the same type

The program compiles fine when I comment out any line telling a list to perform the sort (typically &quot;feat_list.sort()&quot;), so does anyone know what I could be doing wrong?

Cheers for any & all help,
Douglas JL

Common sense is what tells you the world is flat.
 
Im not to familiar with overloading but I think you need to rethink this -

return Famendment_number<rhs.Famendment_number;

return &quot;this is less than this&quot;

what ya trying to do here. try doing it with out the overloading first.

tomcruz.net
 
I think that in C++ a bool value is returned by comparisons, unlike in C where it's an integer value, so that would just be a more optimised way of saying
if(Famendment_number<rhs.Famendment_number)
return true;
else
return false;

However, I'll give it a bash, cuz I ain't solved this yet!
Cheers, man.
DJL

Common sense is what tells you the world is flat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top