在类中调用指针函数

call a pointer function in class

本文关键字:指针 函数 调用      更新时间:2023-10-16

我在类中定义了一个指针函数,并将其用作回调。

课堂是这样进行的

class A
{
    void CreateGrid(OWindow *win,int x,int y);
    Otkobject *GetIcon(void *data,Otkobject *obj,int x)
}

我这样定义了GetIcon函数

Otkobject *A::GetIcon(oid *data,Otkobject *obj,int x){
    //statements
}

对于这个,我得到错误。

Then I try

Otkobject A::*GetIcon(void *data,Otkobject *obj,int x){
    //statements
}

我得到函数名和使用回调。如何使用这个函数指针?

这是一个返回指针的函数,而不是函数指针。错误可能是类声明后缺少分号:

class A
{
    void CreateGrid(OWindow *win,int x,int y);
    Otkobject *GetIcon(void *data,Otkobject *obj,int x); // <- also here
}; // <- notice semicolon

你应该定义这个函数。比如:
typepedef Otkobject *function_type(void *data,Otkobject *obj,int x);

然后你可以在任何你想要的地方使用函数指针