在C++中定义类成员函数指针

来源:互联网 发布:阿里云企业邮箱 付费 编辑:程序博客网 时间:2024/05/06 08:49

转载自:http://www.cppblog.com/shaker/archive/2006/09/01/11924.html

一般的函数指针定义是这样的:

/*****************code begin*****************/
typedef return_type (*fFunctionPoint) ( ... );
/*****************code end******************/

类成员函数是不能被转化成类似上例中的fFunctionPoint类型的.
定义指向类成员函数的指针类型,如下:

/*****************code begin*****************/
typedef
return_type (class_name::*fMemberFunctionPoint) ( ... );
/*****************code end******************/

调用的时候使用

/*****************code begin*****************/
class_name
* Object;
fMemberFunctionPoint MemberFunc;
((*Object).*(MemberFunc))( ... );
/*****************code end******************/

原创粉丝点击