How to create an array of function pointers in C / C++
How to create an array of function pointers in C / C++
4
Author: Nicolas Chabanovsky, 2010-10-20
3 answers
void (*pfn_MyFuncType[10])(char * str, int len);
Or
void (**pfn_MyFuncType)(char * str, int len);
9
Author: Hedgehog, 2011-01-13 11:36:38
You must declare a new type-a pointer to a function. This is done by simply declaring a pointer to a function. Next, you need to declare an array of the function pointer type. For example:
typedef void (*pfn_MyFuncType)(char * str, int len);
pfn_MyFuncType * myFuncTypeArray;
// или
pfn_MyFuncType myFuncTypeArray[10];
5
Author: Nicolas Chabanovsky, 2010-10-21 06:37:54
In the style of c++11
#include <vector>
#include <iostream>
#include <functional>
void foo(int i) {
std::cout << i << '\n';
}
int main() {
std::vector<std::function<void(int)>> vfunc;
vfunc.push_back(foo);
vfunc[0](1);
return 0;
}
0
Author: Andrio Skur, 2019-03-19 13:08:02