But guys, we are not overloading ++ for a pointer, but for objects of test_class. The only thing we are doing is using a pointer as a way of identifying the test_class_object.
The argument to operator++ (as a non-member function) is the operand.
Code:
test operator++(test *b)
{
b->a=b->a+1;
return *b;
}
If this was allowed, the usage would look like
Code:
test* p = new test;
++p; //would not increment the pointer!?
I don't understand the second part of the question. The proper way to overload pre- and postfix increments (as non-member functions) looks like this:
Code:
X& operator++(X& x) //++x
{
x.increment(); //whatever
return x;
}
X operator++(X& x, int) //x++
{
X before_increment = x;
++x;
return before_increment;
}