我有一個具有預分配緩衝區的容器類。我調用memset()來使用預先分配的內存來創建我的對象。由於我沒有使用新的構造函數,因此不會調用它。調用模板類的構造函數
這裏是add函數
template<typename T>
T* CContainer<T>::Add()
{
memset(&m_pBuffer[index],0,index);
T* pReturnValue = reinterpret_cast<T*> (&m_pBuffer[index]);
return pReturnValue;
}
的簡化版本的任何方法來調用模板類T.
感謝您的幫助的構造。
使用「放置新的」。 [這](http://stackoverflow.com/questions/222557/what-uses-are-there-for-placement-new)有一個很好的解釋。 –