GotW #5 Solution: Overriding Virtual Functions -- Herb Sutter

The solution to GotW #5 is now available:

GotW #5 Solution: Overriding Virtual Functions (updated for C ++11/14)

by Herb Sutter

From the article:

Exactly one of the following can be true for a polymorphic type:

  • Either destruction via a pointer to base is allowed, in which case the function has to be public and had better be virtual;
  • or else it isn’t, in which case the function has to be protected (private is not allowed because the derived destructor must be able to invoke the base destructor) and would naturally also be nonvirtual (when the derived destructor invokes the base destructor, it does so nonvirtually whether declared virtual or not).

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.