// overloading operators example #include using namespace std; class Vector { public: int x,y; Vector () {}; Vector (int,int); Vector operator + (Vector); }; Vector::Vector (int a, int b) { x = a; y = b; } // To overload an operator in order to use it with classes we declare operator // functions, which are regular functions whose names are the operator keyword // followed by the operator sign that we want to overload. Vector Vector::operator+ (Vector param) { Vector temp; temp.x = x + param.x; temp.y = y + param.y; return (temp); } int main () { Vector a (3,1); Vector b (1,2); Vector c; c = a + b; cout << c.x << "," << c.y; getchar(); return 0; }