How does C++ free the memory when a constructor throws an exception and a custom new is used

前端 未结 5 1102
春和景丽
春和景丽 2021-02-19 16:07

I see the following constructs:

  • new X will free the memory if X constructor throws.

  • operator new() can be

5条回答
  •  不要未来只要你来
    2021-02-19 16:21

    When a constructor throws an exception the matching delete is called. The destructor is not called for the class that threw but any components of the class that have successfully had their constructors called will have their destructors called.

提交回复
热议问题