函数指针的入门问题

来源:百度知道 编辑:UC知道 时间:2024/09/21 19:56:12
#include<iostream>

using std ::cout;
using std ::endl;

class A
{
void (*fun)(void);
};

class B
{
void output(void)
{
cout<<"this is B"<<endl;
}
};

int main()
{
A a;
B b;
a.fun = b.output();
a.fun();

return 0;
}

我的想法就是用a的成员函数指针取b的成员函数地址。不知道怎么取,谁能教我

class A
{
public:
void (*fun)(void);
};

class B
{
public:
static void output(void)
{
cout<<"this is B"<<endl;
}
};

int main(
{
A a;
B b;
a.fun = &B::output;
a.fun();

return 0;
}

没见过这麼用的!