Using placement new in a container
问题 I just came across some container implementation in C++. That class uses an internal buffer to manage its objects. This is a simplified version without safety checks : template <typename E> class Container { public: Container() : buffer(new E[100]), size(0) {} ~Container() { delete [] buffer; } void Add() { buffer[size] = E(); size++; } void Remove() { size--; buffer[size].~E(); } private: E* buffer; int size; }; AFAIK this will construct/destruct E objects redundantly in Container() and