Description 下麵程式的輸出結果是: destructor B destructor A 請完整寫出 class A。 限制條件:不得為 class A 編寫構造函數。 ~~~~ include using namespace std; class A { // Your Code Her ...
Description
下麵程式的輸出結果是:
destructor B
destructor A
請完整寫出 class A。 限制條件:不得為 class A 編寫構造函數。
#include <iostream>
using namespace std;
class A {
// Your Code Here
};
class B:public A {
public:
~B() { cout << "destructor B" << endl; }
};
int main() {
A * pa;
pa = new B;
delete pa;
return 0;
}
實現代碼
#include <iostream>
using namespace std;
class A {
public:
virtual ~A() { cout << "destructor A" << endl; }
};
class B:public A {
public:
~B() { cout << "destructor B" << endl; }
};
int main() {
A * pa;
pa = new B;
delete pa;
return 0;
}