Function overloading

Somewhat similar to templates, function overloading is another way in which we can make code and classes more versatile. We've already used overloaded functions during the course of the book, but they were provided with the code base. So, let's take a quick look at them.

When we define functions, we set fixed parameter types. Here's an example:

void DoStuff(T parameter);

With this definition, we can only pass a parameter of the T type. What if we want a choice of parameters? What if we want to be able to pass parameters of type T or type Y. Well, we can redefine the function, setting the same return type and name, but with unique parameters:

void DoStuff(T parameter);
void DoStuff(Y parameter);

We now have two function declarations ...

Get Procedural Content Generation for C++ Game Development 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.