13.17 — Nested types in classes

Consider the following short program: #include <iostream> enum class FruitType { apple, banana, cherry }; class Fruit { private: FruitType m_type {}; int m_percentageEaten { 0 }; public: Fruit(FruitType type) : m_type { type } { } FruitType getType() const { return m_type; } int getPercentageEaten() const { return m_percentageEaten; …

18.10 — Dynamic casting

Way back in lesson , we examined the concept of casting, and the use of static_cast to convert variables from one type to another. In this lesson, we’ll continue by examining another type of cast: dynamic_cast. The need for dynamic_cast When dealing with polymorphism, you’ll often encounter cases where you …

18.9 — Object slicing

Let’s go back to an example we looked at previously: class Base { protected: int m_value{}; public: Base(int value) : m_value{ value } { } virtual const char* getName() const { return “Base”; } int getValue() const { return m_value; } }; class Derived: public Base { public: Derived(int value) …