2

I know that delete operator with placement parameters cannot be called from the an invocation of "delete" operator.

For example, the example below can't compile:

class C {
public:
  ...
  void *operator new(unsigned int s, MyAllocator& a) { return a.allocate(s); }
 void operator delete(void *p, MyAllocator& a) { a.free(p); }
};

...

MyAllocator a;
C *p = new(a) C;
...
delete (a) p;    // compilation error

I know also that the good way to achieve is to do:

p->~C();
a.free(p);

But my question is not about syntax or the way to code it in C++ but about the reasons preventing the use of placement parameters in the delete operator invocation (while it is allowed wit new).

0 Answers0