#include <iostream> class test{ private: typedef int (test::*func)(int); public: int getInt(int arg) { return arg; } int getChar(int arg) { return arg; } void Test() { func getd = &test::getInt; std::cout<<(this->*getd)(10)<<std::endl; getd = &test::getChar; std::cout<<((*this).*getd)('c')<<std::endl; } static void hello() { std::cout<<"hello,I am a static function."<<std::endl; } }; int main() { test ta; ta.Test(); typedef int (test::*func)(int); func getD = &test::getInt; std::cout<<(ta.*getD)(10); std::cout<<((&ta)->*getD)(10); void (test::*tfunc)() = &test::Test; (ta.*tfunc)(); ((&ta)->*tfunc)(); void (*hello)() = test::hello; hello(); getchar(); return 0; }
操作符:operator->* 和.*;
Google gtest:http://www.cnblogs.com/coderzh/archive/2009/04/10/1432789.html