Write a c++ program that demonstrate operator overloading for += sign. 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: c++ over load operator
vec2 operator - (vec2 const &other) {
return vec2(x - other.x, y - other.y);
}