mirror of
https://github.com/huihut/interview.git
synced 2024-03-22 13:10:48 +08:00
加个delete
This commit is contained in:
parent
5ff3ab91ad
commit
d91abf8e8c
|
@ -180,7 +180,7 @@ int main()
|
||||||
Base *ptr = new Derived();
|
Base *ptr = new Derived();
|
||||||
ptr->who();
|
ptr->who();
|
||||||
|
|
||||||
// 因为Base有虚析构函数(virtual ~Base() {}),所以调用基类(Base)析构函数,也调用派生类(Derived)析构函数,防止内存泄漏。
|
// 因为Base有虚析构函数(virtual ~Base() {}),所以delete调用基类(Base)析构函数,也调用派生类(Derived)析构函数,防止内存泄漏。
|
||||||
delete ptr;
|
delete ptr;
|
||||||
ptr = nullptr;
|
ptr = nullptr;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user