© Will Briggs 2019
Will BriggsC++ for Lazy Programmershttps://doi.org/10.1007/978-1-4842-5187-4_27

27. Esoterica (Not So Recommended)

Will Briggs
Lynchburg, VA, USA
These features exist; they can be useful in rare circumstances; I hardly ever use them.

protected sections, protected inheritance

Consider the class in Example 27-1. Phone has a member numCalls_ which keeps track of all calls made, ever, by any Phone. There’s a function to change it, but it’s private, because we really should only update numCalls_ when making a call ().
class Phone
    void call() { /*do some stuff, and then */ incNumCalls(); }
    static int numCalls() { return numCalls_; }
    void incNumCalls   () { ++numCalls_;      }
    static int numCalls_;
Example ...

Get C++ for Lazy Programmers: Quick, Easy, and Fun C++ for Beginners now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.