函数std :: vector [英] std::vector of functions

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

问题描述

我希望std :: vector包含一些函数,并且可以将更多函数实时添加到其中.所有功能都将具有这样的原型:

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:

无效名称(SDL_Event * event);

void name(SDL_Event *event);

我知道如何制作函数数组,但是如何制作函数std :: vector?我已经尝试过了:

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

推荐答案

尝试使用typedef:

Try using a typedef:

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

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

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