|
|
发表于 2006-5-1 14:04:58
|
显示全部楼层
可能的用法:- #include <iostream>
- #include <string>
- using namespace std;
- class A {
- public:
- string m_var;
- A() {
- m_var = "Thins is a member variable.";
- }
- int member_f() {
- cout << "This is a member function()." << endl;
- return 0;
- }
- static int static_f() {
- cout << "This is a static function()." << endl;
- return 0;
- }
- };
- int main() {
- A a;
- A *p2a = &a;
-
- int (*p_to_static_f)() = A::static_f;
- string A::*p_to_member_var = &A::m_var;
- int (A::*p_to_member_f)() = &A::member_f;
- p_to_static_f(); //static fucntion
- cout << (a.*p_to_member_var).c_str() << endl;
- (a.*p_to_member_f)();
- cout << (p2a->*p_to_member_var).c_str() << endl;
- (p2a->*p_to_member_f)();
- return 0;
- }
复制代码 |
|