析构函数、虚析构函数、纯虚函数
#include<iostream> using namespace std; class parent { public: parent() { cout << "父类构造" << endl; } ~parent() { cout << "父类析构" << endl; } }; class child :public parent { public: child() { cout << "子类构造" << endl; } ~child() { cout << "子类析构" << endl; } }; int main() { { parent* A = new child(); delete A; } /*父类构造 子类构造 父类析构*/ system("pause"); return 0; }
#include<iostream> using namespace std; class parent { public: parent() { cout << "父类构造" << endl; } virtual ~parent() { cout << "父类析构" << endl; } }; class child :public parent { public: child() { cout << "子类构造" << endl; } virtual ~child() { cout << "子类析构" << endl; } }; int main() { { parent* A = new child(); delete A; } /*父类构造 子类构造 子类析构 父类析构*/ system("pause"); return 0; }
class Box { public: // 纯虚函数 virtual double getVolume() = 0; private: double length; // 长度 double breadth; // 宽度 double height; // 高度 };
https://www.cnblogs.com/-citywall123/p/12745654.html
等风起的那一天,我已准备好一切