From d495d620d8eaa28cb56515bf55547a7035c67c8b Mon Sep 17 00:00:00 2001 From: huihut Date: Wed, 4 Apr 2018 01:27:46 +0800 Subject: [PATCH] =?UTF-8?q?delete=E9=87=8A=E6=94=BE=E5=86=85=E5=AD=98?= =?UTF-8?q?=EF=BC=8C=E6=94=B9=E4=B8=BA=E5=85=88=E8=B0=83=E7=94=A8=E5=AD=90?= =?UTF-8?q?=E7=B1=BB=E6=9E=90=E6=9E=84=EF=BC=8C=E5=86=8D=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E5=9F=BA=E7=B1=BB=E6=9E=90=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d2d1dc1..a4dc290 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,7 @@ int main() Base *ptr = new Derived(); ptr->who(); - // 因为Base有虚析构函数(virtual ~Base() {}),所以delete调用基类(Base)析构函数,也调用派生类(Derived)析构函数,防止内存泄漏。 + // 因为Base有虚析构函数(virtual ~Base() {}),所以delete时,会先调用派生类(Derived)析构函数,再调用基类(Base)析构函数,防止内存泄漏。 delete ptr; ptr = nullptr; @@ -533,7 +533,7 @@ int main() { Shape * shape1 = new Circle(4.0); shape1->calcArea(); - delete shape1; //因为Shape有虚析构函数,所以delete释放内存时,调用基类析构函数,也调用子类析构函数。 + delete shape1; //因为Shape有虚析构函数,所以delete释放内存时,先调用子类析构函数,再调用基类析构函数,防止内存泄漏。 shape1 = NULL; return 0; }