overload opeator in cpp code example
Example 1: c++ operator overloading
// money.h -- define the prototype
class Money
{
public:
Money & operator += (const Money &rhs);
}
// money.cpp -- define the implementation
Money& Money :: operator += (const Money &rhs)
{
// Yadda Yadda
return *this;
}
Example 2: operator = overloading c++
inline bool operator==(const X& lhs, const X& rhs){ /* do actual comparison */ }
inline bool operator!=(const X& lhs, const X& rhs){ return !(lhs == rhs); }