Why there is no placement delete expression in C++?

前端 未结 5 1293
夕颜
夕颜 2020-11-27 05:22

Why C++ hasn\'t placement delete that directly corresponds to the placement new, i.e. calls the destructor and calls appropriate placement delete operator?

For examp

5条回答
  •  忘掉有多难
    2020-11-27 05:39

    Actually there is a placement delete which is called by the implementation for an object that was "allocated" using placement new if the constructor threw an exception.

    From Wikipedia.

    The placement delete functions are called from placement new expressions. In particular, they are called if the constructor of the object throws an exception. In such a circumstance, in order to ensure that the program does not incur a memory leak, the placement delete functions are called.

提交回复
热议问题