#include using namespace std; class X{ int count; public: X(){ count = 0; cout << "Constructor\n"; } ~X(){ cout << "Destructor\n"; } //x = y + z, y is the one invoking the call X operator+ (X x); //++x void operator++ () { cout << "Prefix Operator\n"; ++count; } //x++ void operator++ (int x) { cout << "Overloaded Integer Argument\n"; count++; } //x = y, x will invoke the call X operator=(X x); X operator-(X y); void setcount(int c) {count = c;} int getcount() {return count;} }; X X::operator-(X x1) { X tmp; tmp.count = count - x1.count; return tmp; } X X::operator=(X x) { count = x.count; return *this; } X X::operator+ (X x) { X tmp; tmp.count = count + x.count; return tmp; } // * ? :: . can't be overloaded int main() { X x; x.setcount(10); X y; y.setcount(5); X t = x + y; cout << t.getcount() << endl; //prints 15 ++t; //pre incr calls no arg function cout << t.getcount() << endl; //prints 16 t++; //post incr calls function with int arg type cout << t.getcount() << endl; //prints 17 y = t - y; cout << "Count of Y is " << y.getcount() << endl; //prints 12 x = y = t; cout << "Count of X is " << x.getcount() << endl; //prints 17 return 0; }