typedef

来源:互联网 发布:传奇世界战士技能数据 编辑:程序博客网 时间:2024/06/16 04:39
bool (*pf)(const string&, const string&)
定义了一个函数指针。
如果在前面加上 typedef
typedef bool (*pf)(const string&, const string&)
就定义了一个函数指针类型,可以指向所有形参为const string&, const string&,返回值为bool类型的函数。在把一个函数作为另一个函数的参数是特别实用。
如:
typedef int (*func)(int* ,char )

int function1(int* b,char c)
{
   return 1;
}
int function2(func myfunction,int a)
{
   return 1;                               //可吧形参为const string&, const string&,返回值为int类型的函数作为参数
}

0 0