1

I came across this kind of function signature at multiple sources. It has an argument int but function logic do not use the argument. I am not sure why this is defined in this way ? . If the argument is not need, why not just declare the function with out argument.

  iterator operator--(int) {
     iterator copy(*this);
     operator--();
     return copy;
  }

Thanks

BhanuKiran
  • 2,631
  • 3
  • 20
  • 36

1 Answers1

1

It's a dummy parameter just used to differentiate between the prefix and postfix operators.

The int parameter is a dummy parameter used to differentiate between prefix and postfix versions of the operators. When the user-defined postfix operator is called, the value passed in that parameter is always zero, although it may be changed by calling the operator using function call notation (e.g., a.operator++(2) or operator++(a, 2)).

songyuanyao
  • 169,198
  • 16
  • 310
  • 405