c++成员函数

以前我一直以为类内部的成员函数的参数相当于隐含了一个this指针.比如

class A

{

 int f();

}

我一直认为f的类型是int (*f)(A*),直到最近写一个回调函数的时候才发现原先的理解一直是有误的

看如下代码:

#include <stdio.h>
class A
{
public:
	int f()
	{
		return 0;
	}
};

typedef int (A::*pfun)();
typedef int(*pfun2)(A*);

int main()
{
	A instance1;
	A instance2;
        //pfun p1 = &(instance1.f);
	pfun p1 = &A::f;
	//pfun2 p2 = &A::f;
	printf("%0x",p1);
	return 0;
}

f的类型是pfun而不是pfun2.

posted @ 2014-09-17 20:59  core!  阅读(221)  评论(0编辑  收藏  举报