Programming, Gaming and Computing

Pointing at Things That do Stuff!

Introduction

Pointers in C++ are probably one of the most powerful aspects of programming using the language. They can allow you to easily pass data around with using additional memory and provide a very efficient way to access variables from elsewhere in the program.

But, that’s not all they can do. A very useful, yet not very often used, application of pointers is to be able to point to a function.

How Does it Work?

To be able to store a pointer to a function is relatively simple. You only need to know the return type and the parameters of the function you want to point to.

Now, again, in this example we could have accessed the function directly by name, but if you imagine instead that the CallOutputFunction function is instead a method within a class, it would be possible to effectively program something around a function that doesn’t yet exist, and then pass the function as a pointer.