简单示例
class Test
{
public:
Test(){ std::cout << "Test()" << std::endl; };
void show() { std::cout << "show()" << std::endl; }
static void fun(){ std::cout << "fun()" << std::endl; }
int a;
static int b;
};
int Test::b;
int main()
{
Test t1;
Test *t2 = new Test();
int Test::* p = &Test::a;
t1.*p = 200;
std::cout << t1.*p << std::endl;
t2->*p = 300;
std::cout << t2->*p << std::endl;
int * q = &Test::b;
*q = 400;
std::cout << *q << std::endl;
void (Test::*pf)() = &Test::show;
(t1.*pf)();
(t2->*pf)();
void (*pfun)() = &Test::fun;
pfun();
return 0;
}
|