// class
class MyClass
{
public:
void doIt() const
{
cout << "It works!" << endl;
}
void(MyClass::*fPtr)() const;
};
// main
MyClass *t = new MyClass;
// store function address
t->fPtr = &MyClass::doIt;
(*(t->fPtr))(); // Whats wrong with this line?
如何调用存储在 fPtr 中的函数?当我尝试 (*(t->fPtr))(); 编译器给出了这些错误:
错误 C2171:“*”:在“void (__thiscall MyClass::*)(void) const 类型的操作数上非法
错误 C2064:术语不计算为采用 0 个参数的函数