在指定的地址构造对象,又不会生成对象,就是不用析构该对象。一般是在缓冲区里构造。
可以指定地址,由模板编译类型,还可以传入参数。
#include <new>
template<class T>
inline void constructInPlace(T *_Ptr)
{ // construct object at _Ptr with value _Val
new ((void *)_Ptr) T( );
}
template<class _Ty,class _TParam>
inline void constructInPlace(_Ty *_Ptr,_TParam param)
{ // construct object at _Ptr with value _Val
new ((void *)_Ptr) _Ty( param );
}
template<class _Ty,class _TParam1,class _TParam2>
inline void constructInPlace(_Ty *_Ptr,_TParam1 param1,_TParam2 param2)
{