【发布时间】:2011-12-21 19:33:36
【问题描述】:
// 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 个参数的函数
【问题讨论】:
-
(t->*(t->fPtr))()我认为应该可以工作 -
@KoKuToru:这也是错误的。
-
@KoKuToru:你能发表你的评论作为答案吗?
标签: c++ member-function-pointers