注册 登录
编程论坛 C++教室

如何使用成员函数指针来调用类中的成员函数?

libinden71 发布于 2019-04-28 17:52, 1687 次点击
class tagClass
{
public:
    tagClass();
    ~tagClass();
    void fnA();
    void fnPointer();

   void(tagClass::*p)();
};

void tagClass::fnA()
{
    cout << "fnA" << endl;
}

void tagClass::fnPointer()
{
    this->p= &tagClass::fnA;
}

int main()
{
    CClass c;

    c.fnPointer();
    // (c.*p)();这样写编译错误,不知道要怎么调用。
}

谁帮我看看这个要怎么调用?
2 回复
#2
rjsp2019-04-29 00:00
(c.*c.p)();

另外,不要做无意义的顶帖
#3
libinden712019-04-29 17:25
回复 2楼 rjsp
多谢版主大人!
1