© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023
S. DmitrovićModern C++ for Absolute Beginnershttps://doi.org/10.1007/978-1-4842-9274-7_25

25. Classes – Inheritance and Polymorphism

Slobodan Dmitrović1  
(1)
Belgrade, Serbia
 

In this chapter, we discuss some of the fundamental building blocks of object-oriented programming, such as inheritance and polymorphism.

Inheritance

We can build a class from an existing class. It is said that a class can be derived from an existing class. This is known as inheritance and is one of the pillars of object-oriented programming, abbreviated as OOP. To derive a class from an existing class, we write:
class MyDerivedClass : public MyBaseClass {};
A simple example would be
class ...

Get Modern C++ for Absolute Beginners: A Friendly Introduction to the C++ Programming Language and C++11 to C++23 Standards 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.