如下:
#include <stdio.h>
typedef int ( *FUNC )( void *param );
class CA
{
public:
CA();
void init(FUNC fun){};
};
class CB
{
public:
CA A;
int B_fun(void *param)
{
return 0;
}
public:
void test()
{
A.init(B_fun);
}
};
int main()
{
return 0;
}
编译出错:
> 正在对“Debug\Temptest.unsuccessfulbuild”执行 Touch 任务。
1>ClCompile:
1> main.cpp
1>e:\test\temptest\temptest\main.cpp(23): error C3867: “CB::B_fun”: 函数调用缺少参数列表;请使用“&CB::B_fun”创建指向成员的指针
正确修改:
#include <stdio.h>
typedef int ( *FUNC )( void *param );
class CA
{
public:
CA();
void init(FUNC fun){};
};
class CB
{
public:
CA A;
static int B_fun(void *param)
{
return 0;
}
public:
void test()
{
A.init(B_fun);
}
};
int main()
{
return 0;
}
</