2

How do I do this in C++? I know how to create a pointer to a function but that requires having a name for that pointer.
What I actually need is to somehow create a pointer without naming it. I know the syntax for array of ptr to functions. This might help:

out-type (*ptr[size])(parameters...)

2 Answers 2

12

You should really use a boost/std::function<out_type(parameters)> instead. However, to answer the question at hand, you could use a typedef

typedef out_type(*typedef_name)(param_types);
std::vector<typedef_name> vec;

Or you can just supply the vector with the type directly.

std::vector<out_type(*)(param_types)> vec;
Sign up to request clarification or add additional context in comments.

1 Comment

+1, answers direct question and even suggests better alternative.
4
typedef void (*ptr)(parameters...);
std::vector<ptr> v;

Comments

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.