operator overload 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++
class Point
{
public:
Point& operator++() { ... } // prefix
Point operator++(int) { ... } // postfix
friend Point& operator++(Point &p); // friend prefix
friend Point operator++(Point &p, int); // friend postfix
// in Microsoft Docs written "friend Point& operator++(Point &p, int);"
};