미리 할당 된 버퍼가있는 컨테이너 클래스가 있습니다. 미리 할당 된 메모리를 사용하여 객체를 만드는 memset()을 호출합니다. new를 사용하지 않기 때문에 생성자는 호출되지 않습니다.템플릿 클래스의 생성자를 호출합니다.
다음은 템플릿 클래스 T. 도와
감사의 생성자를 호출 할 수있는 방법 추가 기능
template<typename T>
T* CContainer<T>::Add()
{
memset(&m_pBuffer[index],0,index);
T* pReturnValue = reinterpret_cast<T*> (&m_pBuffer[index]);
return pReturnValue;
}
의 단순화 된 버전입니다.
사용 "새로운 배치를". [이] (http://stackoverflow.com/questions/222557/what-uses-are-there-for-placement-new) 좋은 설명이 있습니다. –