3.2 When to use non-virtual methods

Non-virtual methods are not object specific at run-time. Instead, they are pointer-type specific at compile time. This means that if you need to specific exactly which method (from which class) to use at compile time, you should use a non-virtual methods.

In our example, objects of subclasses of Student use the Student::getTranscript. when they are pointed to by Student pointers. This permits the compile time context dictate which method to use.


Copyright © 2006-10-05 by Tak Auyeung