\
class C{\
public:\
void fun( void (C::\*p)() ){ (this-\>\*p)(); }\
\
void f1(){ cout \<\< "f1" \<\< endl; }\
void f2(){ cout \<\< "f2" \<\< endl; }\
void f(){ fun( &C::f1 ); }\
void ff(){ fun(&C::f2); }\
\
};\
\
int main(){\
C c;\
c.f();\
c.ff();\
}
\
class B{\
public:\
void fun(){ cout \<\< "fun" \<\< endl; }\
void fun2(){ cout \<\< "fun2" \<\< endl; }\
};\
\
B b;\
class C{\
public:\
void fun( void (B::\*p)() ){ (b.\*p)(); }\
\
void f1(){ fun( &B::fun ); }\
void f2(){ fun(&B::fun2); }\
\
};\
\
int main(){\
C c;\
c.f1();\
c.f2();\
}
\
class B{\
public:\
void fun(){ cout \<\< "fun" \<\< endl; }\
void fun2(){ cout \<\< "fun2" \<\< endl; }\
};\
\
class C{\
public:\
void fun( B &b, void (B::\*p)() ){ (b.\*p)(); }\
\
void f1(){ B b; fun( b, &B::fun ); }\
void f2(){ B b; fun(b, &B::fun2); }\
\
};\
\
int main(){\
C c;\
c.f1();\
c.f2();\
}
\
class B{\
public:\
void fun( B &b ){ cout \<\< "fun" \<\< endl; }\
void fun2(B &b ){ cout \<\< "fun2" \<\< endl; }\
};\
\
class C{\
public:\
void fun( B &b, void (B::\*p)(B &c) ){ B d; (b.\*p)(d); }
// 函数指针就只能传递函数指针,参数就不能传递了...\
\
void f1(){ B b; fun( b, &B::fun ); }\
void f2(){ B b; fun(b, &B::fun2); }\
\
};\
\
int main(){\
C c;\
c.f1();\
c.f2();\
}