0

If I want an array of pointers to something, I declare it like this:

Type** var = new Type*[8];

and use it like this:

if(var[0] != NULL)
    // Do something

But how can I have an array of function pointers in a similar fashion? Something like this maybe:

typedef bool (*Handler)(int, int);
Handler** list = new Handler*[8];

...

Handler* func = list[0];
if(func != NULL)
    *func(6, 5);

1 Answer 1

2

You would have:

typedef    bool (*Handler)(int, int);

Handler* list = new Handler[8];

Handler func = list[0];
if (func != NULL)
    func(6, 5);

Just don't put an extra *

Sign up to request clarification or add additional context in comments.

3 Comments

I love you. Now I feel silly... (will accept answer when SO allows me)
Function pointers syntax can be sometimes confusing, methods pointers is another funny thing :D
Nitpick but you can put in the * you just have to bracket it correctly, (*func)(6, 5);. This was the original C syntax (which is why I still find myself using it) but at some point the * became optional.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.