基本定义和使用
定义bool (fx*)(int)
赋值 fx = 函数名
使用 fx(5)或(fx*)(5)
类成员函数的指针
定义bool (Foo::*fx)(int)
赋值fx=&Foo::f
使用:Foo foo; (foo::*fx)(int i)
typedef可以简化函数指针的定义
#include "stdafx.h"
#include <iostream>
int test(int i)
{
return i;
}
void main(int argc, char* argv[])
{
cout<<test<<endl;
typedef int (fx*)(int a) ;//定义一个函数指针的类型
fx pfx;//用定义好的类型定义一个函数指针
pfx = test;
cout<<pfx(5)<<"|"<<(*pfx)(10)<<endl;
cin.get();
}