overload in cpp code example
Example 1: c++ over load operator
// This will substract one vector (math vector) from another
// Good example of how to use operator overloading
vec2 operator - (vec2 const &other) {
return vec2(x - other.x, y - other.y);
}
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);"
};