class Foo
{
public:
Foo () :a (1) {}
int get_value () const{ return a; }
private:
int a;
};
ostream &operator<<(ostream &os, const Foo &f)
{
os << "the Foo's value is: " << f.get_value ();
return os;
}
bool operator==(const Foo &lhs, const Foo &rhs)
{
return lhs.get_value () == rhs.get_value ();
}
bool operator!=(const Foo &lhs, const Foo &rhs)
{
return !(lhs == rhs);
}
bool operator<(const Foo &lhs, const Foo &rhs)
{
return lhs.get_value () < rhs.get_value ();
}
bool operator>(const Foo &lhs, const Foo &rhs)
{
return (((lhs != rhs) && !(lhs < rhs))?
true:false);
}
运算符重载
最新推荐文章于 2016-02-29 11:47:38 发布