【发布时间】:2011-09-14 19:29:03
【问题描述】:
如何将函数作为参数传递然后执行它。我正在尝试做这样的事情:
class Foo{
private:
void (*external);
public:
Foo(void (*function)()){ *external = *function; }
~Foo(){ }
bool Execute(){
*external(); // Somehow execute 'external' which does the same thing with 'function'
return true
}
};
void pFnc(){
printf("test");
}
int main(){
Foo foo = Foo(&pFnc);
foo.Execute();
return 0;
}
这当然行不通。
【问题讨论】:
标签: c++ function pointers arguments void