Contents Up << >>

Should a derived class replace ("override") a non-virtual fn from a base class?

It's legal, but it ain't moral.

Experienced C++ programmers will sometimes redefine a non-virtual fn for efficiency (the alternate implementation might make better use of the derived class' resources), or to get around the hiding rule (see below, and ARM ["Annotated Reference Manual"] sect.13.1). However the client-visible effects must be identical, since non-virtual fns are dispatched based on the static type of the ptr/ref rather than the dynamic type of the pointed-to/referenced object.