13年题。

This commit is contained in:
unlockable
2023-06-02 00:03:58 +08:00
parent 955977fef2
commit 9cecf352c2
11 changed files with 401 additions and 0 deletions

43
OOP/13Exam/3.2.cpp Normal file
View File

@@ -0,0 +1,43 @@
#include <iostream>
using namespace std;
class A {
public:
A() {
cout << "A::A() called.\n";
}
virtual ~A() {
cout << "A::~A() called.\n";
}
};
class B: public A {
public:
B(int i) {
cout << "B::B() called.\n";
buf = new char[i];
}
virtual ~B() {
delete [] buf;
cout << "B::~B() called.\n";
}
private:
char *buf;
};
void fun(A *a) {
delete a;
}
int main() {
A *a = new B(15);
fun(a);
}
/*
A::A() called.
B::B() called.
B::~B() called.
A::~A() called.
*/