Here, try this. The trick is the dummy parameter (int) in the pre-increment
operator, which is used to disambiguate the ++foo and foo++ operators.
dave
class foo
{
public:
foo( int i )
:_i(i)
{}
foo()
:_i(0)
{}
// pre-increment ++foo
foo operator++()
{
_i++;
return *this;
}
// post increment foo++
foo operator++(int )
{
foo tmp = *this;
_i++;
return tmp;
}
int toInt()
{
return _i;
}
private:
int _i;
};
#include "stdafx.h"
int main(int argc, char* argv[])
{
foo f(10);
foo g(10);
foo gnew(++g);
foo fnew(f++);
int gi = g.toInt();
int fi = f.toInt();
int gnewi = gnew.toInt();
int fnewi = fnew.toInt();
return 0;
}
"dover" <do*****@close.com> wrote in message
news:p8********************@bgtnsc05-news.ops.worldnet.att.net...
Could somebody give hints about writing overloading of post-increment and
pre-increment operators? Thanks!