Calling the Postfix Operators Explicitly

As we saw on page 553, we can explicitly call an overloaded operator as an alternative to using it as an operator in an expression. If we want to call the postfix version using a function call, then we must pass a value for the integer argument:

StrBlobPtr p(a1); // p points to the vector inside a1p.operator++(0);  // call postfix operator++p.operator++();   // call prefix  operator++

The value passed usually is ignored but is necessary in order to tell the compiler to use the postfix version.

Exercises Section 14.6

Exercise 14.27: Add increment and decrement operators to your StrBlobPtr class.

Exercise 14.28: Define addition and subtraction for StrBlobPtr so that these operators implement pointer arithmetic ...

Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.