Running method while destroying the object

前端 未结 8 1582
抹茶落季
抹茶落季 2021-01-12 22:49

A few days ago my friend told me about the situation, they had in their project. Someone decided, that it would be good to destroy the object of NotVerySafeClass

8条回答
  •  情话喂你
    2021-01-12 23:32

    Sounds like a horrible design. Can't you use smart pointer to make sure the object is destroyed only when no-one holds any references to it?

    If not, I'd use some external synchronization mechanism. Synchronizing the destructor with a method is really awkward.

提交回复
热议问题