有一个库文件和一个用户函数appUserFunc()。如何将此函数传递给数组单元格commands[]。
#include "lib.h"
void appUserFunc(){ cout << "appUserFunc" << endl;}
int main()
{
runTask();
}
文件 lib.h
#ifndef LIB_H
#define LIB_H
#include <iostream>
using namespace std;
void appSystemFunc(){ cout << "appSystemFunc" << endl;}
struct App
{
int num;
string text;
void (*f)(void);
};
App commands[]
{
{1, "app system", appSystemFunc},
{1, "app system", appUserFunc},
};
void runTask()
{
for(App comm : commands)
{
comm.f();
}
}
#endif