Polymorphism and Overloading in C++

A reader sent me an interesting question the other day. They asked if polymorphism and overloading were essentially the same thing.

My initial reaction was Huh?

What are people being taught if they think that these two concepts are the same thing?

But a quick google search revealed that yes, many, many people are struggling to differentiate between these two terms – and the internet is full of conflicting and unhelpful information.

Read morePolymorphism and Overloading in C++

Overriding or Overloading in C++?

Occasionally I’ve heard these terms used interchangeably – but they actually refer to two completely separate concepts.

So what’s what?

Overloading describes the creation of a method with the same name as an existing method, but different parameters. For example:

int method();
int method(int);
int method(int, double);

Overriding describes the creation of a method in a derived class  with the same name and parameters as an existing method in its base class.

class base {
public:
    int method();
};

class derived : public base
{
public:
    int method();
};

The actual method that is called in this case depends on what kind of object you are dealing with, and whether the base class is abstract, the methods are virtual, and so on.

How do you remember the difference?

Think of it as load versus ride.

Overloading gives you loads of methods in the same class with different parameters.

Overriding lets you ride on the back of a method declared in a base class.

Easy, eh?