创建指向函数的指针的向量 [英] Creating a vector of pointer to functions

查看:93
本文介绍了创建指向函数的指针的向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C ++中做到这一点? 我知道如何创建指向函数的指针,但这需要为该指针命名.
我真正需要的是以某种方式创建指针而不命名它. 我知道ptr函数数组的语法.这可能会有所帮助:

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

推荐答案

您应该真正使用boost/std::function<out_type(parameters)>代替.但是,要回答当前的问题,您可以使用typedef

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;

这篇关于创建指向函数的指针的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆