Overloading + C++ code example
Example 1: operator overloading in c++ <<
ostream &operator<<(ostream &output, const MyClass &myObject)
{
output << "P : " << myObject.property;
return output;
}
Example 2: c++ operator overloading
class Money
{
public:
Money & operator += (const Money &rhs);
}
Money& Money :: operator += (const Money &rhs)
{
return *this;
}
Example 3: operator = overloading c++
inline bool operator==(const X& lhs, const X& rhs){ }
inline bool operator!=(const X& lhs, const X& rhs){ return !(lhs == rhs); }