PS:用函数指针访问类内部函数约束
1不能访问private
#include "iostream"
using namespace std;
class A
{
private:
void fun()
{
cout<<"this is 0"<<endl;
}
public:
void fun1()
{
cout<<"this is 1"<<endl;
}
static void fun2()
{
cout<<"this is 2"<<endl;
}
virtual void fun3()
{
cout<<"this is 3"<<endl;
}
};
int main()
{
//方式1,访问类内部static函数
typedef void (*pfun)();
pfun p=A::fun2;
(*p)();
///
//方式2,访问类内部static函数
void (*pf)();
pf=A::fun2;
(*pf)();
//方式3,访问类内部public函数
void (A::*pf1)();
A a;
pf1=&A::fun1;
(a.*pf1)();
/
//方式4,访问类内部virtual函数
typedef void (A::*pf2)();
pf2 pf2_1=&A::fun3;
(a.*pf2_1)();
return 1;
}