1. Computing

Learn about C++ Classes and Objects

By

7 of 9

What is Polymorphism?
Polymorphism is a generic term that means 'many shapes'. In C++ the simplest form of Polymorphism is overloading of functions, for instance several functions called SortArray( arraytype ) where sortarray might be an array of ints, or doubles.

We're only interested here though in the OOP form of polymorphism. This is done by making a function (e.g. Draw() ) virtual in the base class Point and then overriding it in the derived class Circle.

Although the function Draw() is virtual in the derived class Circle, this isn't actually needed- it's a reminder to me that this it is virtual. If the function in a derived class matches a virtual function in the base class on name and parameter types, it is automatically virtual.

Drawing a point and drawing a circle are too very different operations with only the coordinates of the point and circle in common. So it's important that the correct Draw() is called. How the compiler manages to generate code that gets the right virtual function will be covered in a future tutorial.

On the next page : Learn about Constructors.

  1. About.com
  2. Computing
  3. C / C++ / C#
  4. C++ Programming
  5. Learn C++ Programming
  6. What is Polymorphism?

©2014 About.com. All rights reserved.