小编Ale*_*Kul的帖子

C++:指向另一个类函数的函数指针

我有2节课

class B {
public:
    int func(int i);
};

class A {
public:
    typedef int (B::*fPtr)(int);
    void run();
    B* mB;
};

void A::run() {
    // create a pointer
    fPtr p = &(B::func);
    // invoke the function
    mB->*p(2);     <------- Compilation Error
}
Run Code Online (Sandbox Code Playgroud)

我需要的是在A的运行函数中创建一个指向func()的指针.我得到一个编译错误,说mB不对应于带有1个参数的函数.

请帮忙

c++ pointers function

3
推荐指数
1
解决办法
6835
查看次数

标签 统计

c++ ×1

function ×1

pointers ×1