Function c++;将成员函数指针作为参数传递

Function c++;将成员函数指针作为参数传递,function,pointers,parameters,Function,Pointers,Parameters,我已经阅读了很多关于成员函数指针的帖子,但似乎没有一个建议的解决方案适用于我的情况。我在这些帖子中学会了如何声明成员函数指针,所以我有一个类似这样的类: Class A { // some members over here B registar; int (A::cb) (int, void*); // my function pointer int callback(int, void* args); // the function I nee

我已经阅读了很多关于成员函数指针的帖子,但似乎没有一个建议的解决方案适用于我的情况。我在这些帖子中学会了如何声明成员函数指针,所以我有一个类似这样的类:

Class A {
    // some members over here
    B  registar;

    int (A::cb) (int, void*);      // my function pointer

    int callback(int, void* args); // the function I need to call in method1()

    A(): cb(&A::callback) {}

    int method1()
    { 
        //need to access member variables here and construct args
        char* args;

        // this is where I need to pass callback(int, void*) as a parameter to somewhere.
        // what I want to achieve is something like 
        // registar.register(callback, args)
    } 
}
因此,我试图将回调作为参数传递给method1()中的某个函数,如上所述。 我需要怎么做

我看的例子是

class A {
    public:
    int f();
     int (A::*x)(); // <- declare by saying what class it is a pointer to
};

int A::f() { return 1;}

int main() {
     A a;
     a.x = &A::f; // use the :: syntax
     printf("%d\n",(a.*a.x)()); // use together with an object of its class
} 
A类{
公众:
int f();

int(A::*x)(;//我从registar.register(回调,args)得到的错误是“错误:必须调用对非静态成员函数的引用”
register()
?@Slaks通过调用registar.register(),回调在registar中注册,稍后将由registar调用。