Can i call destructor from its class method?

前端 未结 1 1030
梦如初夏
梦如初夏 2021-02-15 03:42

I have a Thread class like bellow

class Thread {
public:
  Thread();
  ~Thread();
  void start();
  void stop();
}

So i need to call destructor

相关标签:
1条回答
  • 2021-02-15 04:07

    Yes

    delete this;
    

    But be careful. You should not use the deleted object, this and non-static members anymore.

     

    Another way is to call destructor

    ~Thread();
    

     

    But the question is, why do you need call the destructor?! It's not logical. You can write a code to manage the resources in a private method and call it.

    0 讨论(0)
提交回复
热议问题