【发布时间】:2015-10-08 16:03:28
【问题描述】:
有一个结构:
scheduled_call {
MyClass* object;
int value;
void (MyClass::*setter)(const int)
}
类:
MyClass {
void doSomething(const int);
}
结构编译得很好,但是当我尝试将值调用为函数时,它会抛出错误:
我需要执行保存在这个结构中的调用。我试过这个:
void executeIt(scheduled_call cl) {
cl.object->*(cl.method)(cl.value);
}
但我明白了:
error C2064: term does not evaluate to a function taking 1 arguments
我的编码基于C/C++ function pointer guide。我这样做是为了做一个实验,如果失败了,我当然可以退回到switch 声明。
任何人都可以在 Visual Studio 2010 下编译这个吗?
【问题讨论】:
-
This post(第二个答案)是成员函数指针语法的一个很好的参考。