This answer is to the point and concise.
The following source code is an eample for overloading operator ++ and -- for both postfix and prefix versions.
#include <iostream>
using namespace std;
class A
{
public:
A(int i_=0, double d_=0) : i(i_), d(d_) { }
const A operator++(int) /// postfix
{
A old(*this);
//++i;
//++d;
++(*this);
return old;
}
/**
This is an option for the postfix ++. But since it returns void,
we cannot use it in an expression, say (a++) + 1.
*/
//void operator++(int)
//{
// ++(*this);
//}
A& operator++() /// prefix
{
++i;
++d;
return (*this);
}
const A operator--(int)
{
A old(*this);
--i;
--d;
return old;
}
A& operator--()
{
--i;
--d;
return *this;
}
void print() const
{
cout<<"i = "<<i<<", d = "<<d<<endl;
}
private:
int i;
double d;
};
int main(int argc, char** argv)
{
A a(2, 3.4);
a.print();
(a++);
a.print();
++a;
a.print();
//A b(-3, 9.2);
//b.print();
//b--;
//b.print();
//--b;
//b.print();
return 0;
}