Conversions Between Classes Related Through Inheritance

The use of inheritance introduces additional possibilities for using an object of one type where an object of another type is expected. Classes related through public inheritance are not totally incompatible because a derived class object has all the operations and data members that a base class object has. As you are going to see, one can assign an object of one class to an object of another type (possibly using an explicit cast). One can pass an object of one class as an argument where a parameter of another class is expected (again, you might need a cast).

The C++ rules for conversions between classes related through inheritance are not very complex. It seems, however, that they run ...

Get Core C++ A Software Engineering Approach 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.