memcpy(&func2,&phello_fun,sizeof(phello_fun));

#include <stdio.h>
#include <string.h>
class test 
{ 
public: 
	test(int i){ m_i=i;} 
	test(){}; 
	void hello() 
	{ 
		printf("hello\n"); 
	} 
private: 
	int m_i; 
}; 

/*
int main() 
{ 
	test *p=new test(); 
	p->hello(); 
	delete p;
	p=NULL; 
	p->hello(); 
	return 0;
} 
//*/

//*
typedef void (test::*HELLO_FUNC)();
typedef void (*HELLO_FUNC2)();

int main() 
{ 
	test *p=new test(); 
	test q;
	p->hello(); 
	HELLO_FUNC phello_fun=&test::hello;

	HELLO_FUNC2 func2;
	memcpy(&func2,&phello_fun,sizeof(phello_fun));
	(*func2)();
	printf("%p\n",phello_fun);
	p=NULL; 
	phello_fun=&test::hello;
	printf("%p\n",phello_fun);
	phello_fun=p->hello;
	printf("%p\n",phello_fun);
	phello_fun=q.hello;
	printf("%p\n",phello_fun);
	p->hello(); 
	return 0;
} 
//*/

阅读更多
文章标签: fun include null delete
个人分类: c++MFC学习笔记
上一篇cout&lt;&lt;&quot;Press any key to exit!\n&quot;&lt;&lt;endl;
下一篇HELLO_FUNC phello_fun=&amp;test::hello; (p-&gt;*phello_fun)();
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭