Tuesday, August 18, 2009
c++: operators
template< class Derived >class Comparable { public: bool operator !=(const Derived& rhs) {return !( static_cast(*this) == rhs ); } bool operator <(const Derived& rhs) {return rhs < static_cast(*this); } bool operator >=(const Derived& rhs) {return !( static_cast(*this) < rhs ); } bool operator <=(const Derived& rhs) {return !( static_cast(*this) > rhs ); }};struct MyStruct : public Comparable { bool operator ==(const MyStruct & rhs) {return /* whatever */; } bool operator <(const MyStruct & rhs) {return /* whatever */; }};
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment