When you define a class , its members define its memory layout. Class data elements are stored sequentially in memory.
When deriving classes and inheritance is used, data members of the derived class are simply added after the base class.
Thus, when a slice occurs, you effectively “see” only the base classes.
Now, to the question "Why do not pointers to the base class cut objects of the derived class"?
One of the most important aspects of inheritance is not that it provides member functions for the derived class, but that it provides the relationship expressed between the derived class and the base class. A derived class can be thought of as a "type of base class."
For further reading, check the rise and fall conditions.
Upcasting converts a reference to a derived class or a pointer to a base class. In other words, increasing efficiency allows us to process a derived type as if it were its base type.
To answer your questions from the comments section, “What Override?
Getting a function with the same name and type of virtual function from the base class is called the caller.
Ziezi source share