how to refer to the current struct in an overloaded operator?

Posted by genesys on Stack Overflow See other posts from Stack Overflow or by genesys
Published on 2009-08-17T14:15:46Z Indexed on 2010/04/08 3:33 UTC
Read the original article Hit count: 335

Hi!

I have a struct for which i want to define a relative order by defining < , > , <= and >= operators. actually in my order there won't be any equality, so if one struct is not smaller than another, it's automatically larger.

I defined the first operator like this:

struct MyStruct{
...
...

bool operator < (const MyStruct &b) const {return (somefancycomputation);}

};

now i'd like to define the other operators based on this operator, such that <= will return the same as < and the other two will simply return the oposite. so for example for the > operator i'd like to write something like

bool operator > (const MyStruct &b) const {return !(self<b);}

but i don't know how to refere to this 'self' since i can refere only to the fields inside the current struct.

whole is in C++

hope my question was understandable :)

thank you for the help!

© Stack Overflow or respective owner

Related posts about struct

Related posts about operators