13.3 POINTING TO DERIVED CLASS OBJECTS

Theoretically, pointers are pointers. There is no distinction, whether they point to a base class or to a derived class. In a highly disciplined language, these pointers belong to separate type. Pointer to base class is different from pointer to derived class. Just as pointer to int is distinct from pointer to float, pointer to Creature is distinct from pointer to Bird or Pet.

We can perform all normal operations on objects referred to using pointers. We have seen this in an earlier program. There pointer to class Bird was pointing to object of type Bird. There was no problem.

To support polymorphism in an elegant way, C++ makes a special deviation from its highly typed nature. It allows pointer to base ...

Get Object Oriented Programming with C++, Second Edition 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.