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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

operator overloading

Status
Not open for further replies.

zfrsen

Technical User
Joined
Nov 5, 2005
Messages
1
Location
TR
i inherited a TPanel component and tried to overlaod its operator<. but my operation was useless as i saw when i debugged the code, my operator< does not work indeed.
here is what i have done;
this is my class;
class MyClass:public TPanel

this is my operator<;
bool MyClass::operator<(const MyClass* y)const
{
if(w < y->GetW())
{
return false;
}
if(w==y->GetW())
{
if(h < y->GetH())
return false;
else
return true;
}
else
return true;
};

and this is my declaration;
HIDESBASE bool operator<(const MyClass *)const;

what have i forgatten?, any idea?
 
What about it isn't working?

It's kind of strange to see a pointer as the parameter, usually people use references.
Also, it would work better if you made this a non-member non-friend function instead of a class member function.

I think you've got a bug. What if both h and w are equal? In that case, since you're comparing for <, the function should return false, but you're returning true instead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top