What is the full list of actions performed by placement new in C++?

c++, constructor, new-operator

Solution

Placement `new` does everything a regular `new` would do, except allocate memory.

I think you've essentially nailed what happens, with some minor clarifications:

- obviously the constructor of the class itself is called as well

- vtable pointers are initialized as part of constructor calls, not separately. An implication of this is that a partially constructed object (think exceptions thrown in constructor) has its vtable set up to the point the construction proceeded to.

The order of construction/initialization is as follows:

- virtual base classes in declaration order

- nonvirtual base classes in declaration order

- class members in declaration order

- class constructor itself

Problem

In this question creating a factory method when the compiler doesn't support new and placement new is discussed. Obviously some suitable solution could be crafted using malloc() if all necessary steps done by placement new are reproduced in some way. What does placement new do - I'll try to list and hope not to miss anything - except the following? - call constructors for all base classes recursively - call constructors and initializers (if any) for all member variables - set vtable pointer accordingly. What other actions are there?

Original source

Related problems