构造析构顺序

#include <iostream>

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

   ~Person()
   {
      std::cout << "~Person" << std::endl;
   }

private:
};

class Student: public Person
{
public:
   Student()
   {
      std::cout << "Student" << std::endl;
   }

   ~Student()
   {
      std::cout << "~Student" << std::endl;
   }
};

int main()
{
   Student s;

   return 0;
}
$ ./a.out          
Person
Student
~Student
~Person
posted @ 2022-06-30 21:15  thomas_blog  阅读(16)  评论(0编辑  收藏  举报