#include <stdio.h> class base{ //基底クラス public: base(){ printf("base create\n"); } ~base(){ printf("base delete\n"); } }; class test : public base{ public: test(){ printf("test create\n"); } ~test(){ printf("test delete\n"); } }; int main(){ base*obj=new test(); delete obj; return 0; }
base create test create base delete |
#include <stdio.h> class base{ //基底クラス public: base(){ printf("base create\n"); } virtual ~base(){ printf("base delete\n"); } }; class test : public base{ public: test(){ printf("test create\n"); } ~test(){ printf("test delete\n"); } }; int main(){ base*obj=new test(); delete obj; return 0; }
base create test create test delete base delete |