C++ Post increment and pre increment


C++ FAQ suggests the following for post increment.

 class Number {
   Number& operator++ ();    // prefix ++
   Number  operator++ (int); // postfix ++

But actually is should be

const Number operator++(int);

to prevent num++++ which semantically doesn’t make any sense.

Similarily, operator+ should return const Number.

Similar Posts:

Post a Comment

Your email is never published nor shared.