Does calling a destructor explicitly destroy an object completely?

前端 未结 11 1428
日久生厌
日久生厌 2020-12-03 14:43

If I call a destructor explicitly ( myObject.~Object() ) does this assure me that the object will be appropriately destroyed (calling all child destructors) ?

Ok so

11条回答
  •  离开以前
    2020-12-03 14:58

    Please save yourself some real headaches and use the Boost Object Pool, which sounds like an existing implementation of your source/sink pattern. It will allocate large chunks of memory, slice them into the correct size for your object and return them to you (after calling the constructor). When you delete objects, they have their destructor called and are put into a linked list of objects for re-use. It will grow and shrink automatically and ensure that instances of your objects tend to be close together in memory.

    If nothing else, it is a good example implementation of placement new and explicit use of constructors that you could study.

提交回复
热议问题