Popular IV topic. P41 [[more effective c++]] has an excellent summary:
- to BOTH allocate (on heap) and call constructor, use regular q(new)
- to allocate Without construction, use q(operator new)
- You can also use malloc. See https://stackoverflow.com/questions/8959635/malloc-placement-new-vs-new
- to call constructor on heap storage already allocated, use placement-new, which invokes ctor
The book has examples of Case 2 and Case 3.
Note it’s common to directly call constructor on stack and in global area, but on the heap, placement-new is the only way.
Placement-new is a popular interview topic (Jump, DRW and more …), rarely used in common projects.