vc++/c++主动调用构造函数/析构函数

//先申请内存空间
CLASS_NAME *pObject=(CLASS_NAME*)malloc(sizeof(CLASS_NAME));

//主动调用构造函函数
#pragma push_macro("new")
#undef new
    ::new((void*)(pObject))CLASS_NAME;
#pragma pop_macro("new")

//主动调用析构函数
pObject->~CLASS_NAME();

 

BOSS

发表评论

PHP Code Snippets Powered By : XYZScripts.com