C++中几种类型的函数指针
2013-07-26 11:15
246 查看
1. 一般函数的指针定义
int foo(const char *out) { cout << "foo is called: " << out << endl; return strlen(out); } typedef int (FooFunType)(const char*); // 函数的类型别名 typedef int (FooFunPointerType)(const char*); // 函数指针类型的别名 FooFunType* f1 = foo; FooFunPointerType f2 = foo; f1("f1-FooFunType"); f2("f2-FooFunPointerType"); // 输出为: // foo is called: f1-FooFunType // foo is called: f2-FooFunPointerType
2. 成员函数指针的定义
class Foo { public: int Print(const char *out) { cout << "Foo::Print is called: " << out << endl; } }; typedef int (Foo::*FooMemPtr)(const char *out); FooMemPtr clbkFooPrint = &Foo::Print; Foo foo; Foo *pFooObj = &foo; pFooObj->*clbkFooPrint("class member function called.");
相关文章推荐
- C++语法基础--模板实参推断,模板类型形参的实参的受限转换,模板实参推断与函数指针
- 【转】C++函数——指针和引用类型的参数传递
- (Boolan) C++ 类型大小和内存分布(虚函数指针、虚表、内存对齐问题)
- C/C++中的几种类型的指针简析
- C++学习14:使用typedef定义函数指针类型
- C/C++—— 写一个函数,它的参数为指向函数的指针,返回类型也为指向函数的指针
- C++用typedef定义函数指针类型typedef可以用于定义函数指针类型
- C++------------typedef 函数指针类型定义
- C#中调用C++的dll的参数为指针类型的导出函数(包括二级指针的情况)
- c++函数参数类型-值,指针,引用
- C++ 二级指针、函数指针与数组复合类型的问题分析
- c++函数参数类型-引用、指针、值
- C++------------typedef 函数指针类型定义
- C#中调用C++的dll的参数为指针类型的导出函数(包括二级指针的情况)
- c++中函数中变量内存分配以及返回指针、引用类型的思考
- C++强制转换不同声明或类型的函数指针隐患
- C#中调用C++的dll的参数为指针类型的导出函数(包括二级指针的情况)
- c++函数参数类型-引用、指针、值
- C#中调用C++的dll的参数为指针类型的导出函数
- C++强制转换不同声明或类型的函数指针隐患