现在的位置: 首页 > 综合 > 正文

指向类的成员函数的指针

2014年02月05日 ⁄ 综合 ⁄ 共 582字 ⁄ 字号 评论关闭

不知道这个标题有没有表达出我想表达的意思,就是定义一个指向类的成员函数的指针类型.

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

/*****************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******************/

恩 报告完毕

抱歉!评论已关闭.