class Y
{
public:
int x;
static int x_s;
static void Def_S()
{
cout<<"OK"<<endl;
}
void Def()
{
cout<<"KO"<<endl;
}
};
int Y::x_s = 10;
int main()
{
//静态函数引用
void (*ptr)() = & Y::Def_S;
ptr();
//非静态函数引用
Y y;
void (Y::*ptr_s)() = &Y::Def;
(y.*ptr_s)();
//静态变量引用
cout<<"静态变量引用前 Y::x_s:" << Y::x_s <<endl;
int *p_s = &Y::x_s;
*p_s = 20;
cout<<"静态变量引用后 Y::x_s:" << Y::x_s <<endl;
//非静态变量引用
y.x = 30;
cout<<"非静态变量引用前 Y::x_s:" << y.x <<endl;
int Y::*p = &Y::x;
y.*p = 40;
cout<<"非静态变量引用后 Y::x_s:" << y.x <<endl;
return -1;
}
结果: