Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

i guess, this is more an ordinary c++ problem, by convention,

  • operator++() denotes the "postfix" increment (x++)
  • operator++(int) denotes the "prefix" increment (++x)

the int arg in the latter is a dummy, you're not supposed to supply something there (and how would you even?)

the difference between them is the order of evaluation and increment, it's the same as with plain pointers:

int X[] = { 3,4,5,6 };
int *x = X;
cerr << *(x++); // prints 3, first eval, then increment
cerr << *(++x); // prints 5, first increment, then eval

i guess, this is more an ordinary c++ problem, by convention,

  • operator++() denotes the "postfix" increment (x++)
  • operator++(int) denotes the "prefix" increment (++x)

the int arg in the latter is a dummy, you're not supposed to supply something there (and how would you even?)

the difference between them is the order of evaluation and increment, it's the same as with plain pointers:numbers:

int X[] x = { 3,4,5,6 };
int *x = X;
3;
cerr << *(x++); (x++); // prints 3, first eval, then increment
cerr << *(++x); (++x); // prints 5, first increment, then eval

i guess, this is more an ordinary c++ problem, by convention,

  • operator++() denotes the "postfix" increment (x++)
  • operator++(int) denotes the "prefix" increment (++x)

the int arg in the latter is a dummy, you're not supposed to supply something anything there (and how (how would you even?)

the difference between them is the order of evaluation and increment, it's the same as with plain numbers:

int x = 3;
cerr << (x++); // prints 3, first eval, then increment
cerr << (x);   // prints 4 ;)
cerr << (++x); // prints 5, first increment, then eval