#include <iostream> #include <string> using namespace std; class student { public: student() { cout << "constructing student." << endl; shours = 60; gpa = 6; } ~student() { cout << "destructing student." << endl; } private: int shours; int gpa; }; class teacher { public: teacher() { cout << "constructing teacher ." << endl; } ~teacher() { cout << "destructing teacher." << endl; } }; void main() { student stu1; teacher tea1; stu1.~student(); tea1.~teacher(); std::cout << sizeof(student) << endl; cout << "end in main" << endl; }
Destructor explicit call
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326412173&siteId=291194637
Recommended
Ranking