C++ – std::vector of functions

c++functionpointersstdvector

I want a std::vector to contain some functions, and that more functions can be added to it in realtime. All the functions will have a prototype like this:

void name(SDL_Event *event);

I know how to make an array of functions, but how do I make a std::vector of functions? I've tried this:

std::vector<( *)( SDL_Event *)> functions;

std::vector<( *f)( SDL_Event *)> functions;

std::vector<void> functions;

std::vector<void*> functions;

But none of them worked. Please help

Best Solution

Try using a typedef:

typedef void (*SDLEventFunction)(SDL_Event *);
std::vector<SDLEventFunction> functions;