Things to Know About Virtual Methods
We’ve already discussed the main points about virtual methods:
• Beginning a class method declaration with the keyword virtual
in a base class makes the function virtual for the base class and all classes derived from the base class, including classes derived from the derived classes, and so on.
• If a virtual method is invoked by using a reference to an object or by using a pointer to an object, the program uses the method defined for the object type rather than the method defined for the reference or pointer type. This is called dynamic, or late, binding. This behavior is important because it’s always valid for a base-class pointer or reference to refer to an object of a derived type.
• If you’re defining ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.