Defining Prefix Increment/Decrement Operators

To illustrate the increment and decrement operators, we’ll define these operators for our StrBlobPtr class (§ 12.1.6, p. 474):

class StrBlobPtr {public:    // increment and decrement    StrBlobPtr& operator++();       // prefix operators    StrBlobPtr& operator--();    // other members as before};

Image Best Practices

To be consistent with the built-in operators, the prefix operators should return a reference to the incremented or decremented object.

The increment and decrement operators work similarly to each other—they call check to verify that the StrBlobPtr is still valid. If so, check also verifies ...

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.