C++ ClassesLesson 39Free preview
C++ Polymorphism
This lesson is part of C++ · All levels
Summary
Polymorphism allows one interface to be used for many forms: methods with the same name can behave differently on a derivative class. The key is virtual function, which makes the call via a pointer or reference base selecting the version belonging to the actual object. If a class has a pure virtual, it becomes abstract and cannot be directly created as an object.
Key points
- Virtual function can be override in class derived and selected dynamically (runtime).
- The explicit override is written with an override to prevent typing the signature incorrectly.
- Pure virtual is written as virtual void f() = 0; and makes a class abstract.
- Without a virtual, the pointer-base call is always running the base version.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.