本文共 312 字,大约阅读时间需要 1 分钟。
#includeusing namespace std; class A { public: virtual ~A() { cout << "Destroy A" << endl; } }; class B : public A { public: ~B() { cout << "Destroy B" << endl; } }; int main() { A* p = new B; delete p;//如果上面不加virtual,delete p只析构类A//如果加上,先析构B再析构A,正确做法! return 0;}自己把这个程序运行一下就知道了。good luck.
转载地址:http://lwrmb.baihongyu.com/