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
{
public:
void call() { /*do some stuff, and then */ incNumCalls(); }
static int numCalls() { return numCalls_; }
private:
void incNumCalls () { ++numCalls_; }
static int numCalls_;
};