Course Object Oriented Programming

Operator Overloading

Course's Page 14 min Text by
User Image
Allan Garcia

Let's now look at Operator Overload. When we create a class in C++ it is possible to implement the basic operators (bigger, smaller, equal, etc.) for this class, this process is known as operator overload.

Operator Overload Error

Imagine the code below:

class A {
   public:
    int x, y;

    A() {
        x = 0;
        y = 0;
    }
    A(int x, int y) {
        this->x = x;
        this->y = y;
    }
};