char memory[sizeof(Myclass)];
void* place = memory;
Myclass* f = new(place) Myclass();
You are also solely responsible for the destruction of the posted facility. This is done by explicitly calling the destructor:
f->~Myclass();
EDIT
After reading Martin York’s commentary and the relevant section of the Standard, it’s clear that you should not use the above method (using objects pushed onto the stack with new). Use std::vectorinstead placement new, as Martin suggested.
source
share