What are private virtual functions in C ++

Private virtual method in C ++

Despite all calls to declare a virtual member private, the argument just doesn't hold up. Often when a derived class overwrites a virtual function, the base class version must be called. It cannot if it is declared:

you have to declare the base class method.

Then you have to take the ugly means of commenting out that the method should be overridden but not called.

So Herb Sutter's guideline # 3 ... But the horse is out of the stable anyway.

When you declare something, you implicitly trust the writer of a derived class to understand and use the protected internals, as does a - declaration a deeper trust for members.

Users who suffer bad behavior (such as "clueless" not taking the effort to read your documentation) by violating this trust can only blame themselves.

pdate: I've had some feedback that says you can chain virtual function implementations with private virtual functions this way. If so, I would love to see it.

The C ++ compilers I use do not allow an implementation of a derived class to call an implementation of a private base class.

If the C ++ committee relaxed "private" to allow this specific access, I would be all for private virtual functions. As it stands, we are still being advised to lock the barn door after the horse is stolen.