Creating a vector of pointer to functions

别说谁变了你拦得住时间么 提交于 2019-12-07 21:14:40

问题


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...)

回答1:


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;



回答2:


typedef void (*ptr)(parameters...);
std::vector<ptr> v;


来源:https://stackoverflow.com/questions/4198415/creating-a-vector-of-pointer-to-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!