C 从功能数组中调用函数
C++ calling functions from an array of functions
对不起,我是本学期刚刚开始的C 的新手。但我有个问题。我知道JavaScript有些很好,我喜欢它作为一种编程语言的松散。(这既是一件好事又是坏事。)但是,在JavaScript中您可以做一件事,我不确定您是否可以在C 中做。
我想从一系列函数中调用一些函数,这是在JavaScript中完成的链接。JavaScript函数数组。我的想法是写一个for循环,该循环将按照我想要的顺序进行函数。(从第一到最后。)如果有替代方案,我将对此感到满意。我什至可以用它们在它们之后的数字命名函数,例如函数1例如,如果这可能会有所帮助。我不确定这是否可能,但是任何帮助或其他任何东西都会很棒。
您是否谈论"功能指针"?
void f1() { .. }
void f2() { .. }
void f3() { .. }
typedef void (*pf)();
pf arf[3] = { f1, f2, f3 };
arf[0]();
如果您不想使用函数指针
struct parent
{
virtual void f();
}
struct child1 : parent
{
void f(){};
}
struct child2 : parent
{
void f(){};
}
struct child3 : parent
{
void f(){};
}
.
.
.
struct childn : parent
{
void f(){};
}
parent array = {child1,child2,child3,.....,childn};
array[n].f();
each child classes will contain different implementations of f(), so you can
create an array of child structs and invoke the methods through the for loop.
相关文章:
- 如何用参数值调用函数(仅在运行时已知)
- 从python中调用C++函数并获取返回值
- 当使用通配符和null指针调用函数时,对输出的说明
- 从R调用C++函数并对其进行集成时出错
- 使用QTreeView,如何通过调用函数只突出显示特定的行/列
- 如何在qt中从另一个类调用函数
- 在 COUT 语句中使用 COUT 调用函数
- 如何从线程中的不同模块调用函数?
- C++从函数指针数组调用函数
- 当 A 在 for 循环中调用函数 B 时,如何计算函数 A 的空间复杂度?
- 如何在 C/C++ 中从外部库调用函数
- 如何使用运算符在同一行中多次调用函数
- 是否可以创建一个从不同类调用函数的线程?
- 无法为类成员调用函数
- 如何从另一个标头 c++ 调用函数
- C++有什么方法可以在既不调用函数模板也不提供其模板参数的情况下引用函数模板?
- 如何只允许在调用函数 B 后调用函数 A?
- 我可以这样调用函数吗?
- 如何在 c++ 的类中递归调用函数方法?
- 为什么在指向对象的迭代器上调用函数不允许我更改对象本身?