Introducing polymorphism

Polymorphism comes from the Greek for many shapes. So far, you have a basic form of polymorphism. If you use a base class pointer to an object, then you can access the base class behavior, and if you have a derived class pointer, you get the derived class behavior. This is not as trivial as it appears because the derived class can implement its own version of the base class methods, so you can have a different implementation of that behavior.

You can have more than one class derived from a base class:

    class base { /*members*/ };     class derived1 : public base { /*members*/ };     class derived2 : public base { /*members*/ };     class derived3 : public base { /*members*/ };

Since C++ is strongly typed, it means that a ...

Get Beginning C++ Programming 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.