标签:
// PointtoMemberFunction.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <IOSTREAM> using namespace std; class A{ public: void f(){ cout<<"f()"<<endl; } virtual void g(){ cout<<"g()"<<endl; } static void h(){ cout<<"h()"<<endl; } }; int main(int argc, char* argv[]) { A *pa = new A; typedef void (A::*pfuncf)(void); pfuncf testf = &A::f; // printf("%d\n",testf); (pa->*testf)(); typedef void (A::*pfuncg)(void); //与普通成员函数一样 pfuncg testg = &A::g; // printf("%d\n",testg); (pa->*testg)(); typedef void (*pfunch)(void); //类中static看做一般函数,除了下面一行得加上个 A::,其余与一般函数一样 pfunch testh = &A::h; // printf("%d\n",testh); (*testh)(); //使用时,就不需要A::了,与一般函数指针相同 return 0; }
标签:
原文地址:http://www.cnblogs.com/xiumukediao/p/4640870.html