overloading c++ operators code example
Example 1: operator overloading in c++ <<
ostream &operator<<(ostream &output, const MyClass &myObject)
{
output << "P : " << myObject.property;
return output;
}
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);"
};