加个delete

This commit is contained in:
huihut 2018-04-04 01:16:06 +08:00
parent 5ff3ab91ad
commit d91abf8e8c

View File

@ -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;