#include <new>
template <class T>
inline T * CALL_CON( T * ptMem )
{
T * pt = new(ptMem)T;
return pt;
}
template <class T>
inline void CALL_DEC( T * pt )
{
pt->~T();
}
使用方法:
class CTest
{
public:
CTest():m_iTest(100){}
protected:
int m_iTest;
};
....
char testBuffer[256];
CTest * pTest = CALL_CON( (CTest*)testBuffer );
....
CALL_DEC( pTest );