成员变量析构:对象会主动调用析构函数

#include <iostream>
#include <list>

class destructor_test{
public:
  ~destructor_test(){
    std::cout << "~destructor_test" << std::endl;
  }
};

class test{
private:
  destructor_test destructor_test_instance;
};


int main ()
{
  test * test_instance = new test();
  delete test_instance;

  return 0;
}

 

posted @ 2018-09-05 15:30  友哥  阅读(373)  评论(0编辑  收藏  举报