#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; }
析构函数显式调用
猜你喜欢
转载自javaeye-hanlingbo.iteye.com/blog/2408194
今日推荐
周排行