---
title: "C++虚析构函数详解"
author: "星之空"
date: "2015-10-02T18:07:08Z"
tags: []
categories: ["编程语言"]
slug: "c"
draft: false
lastmod: "2015-09-13T18:16:16Z"
id: 2243057
url: "https://986289063.iteye.com/blog/2243057"
---

当派生类的对象从内存中撤销时一般先调用派生类的析构函数，然后再调用基类的析构函数。但是，如果用new运算符建立了临时对象，若基类中有析构函数，并且定义了一个指向该基类的指针变量。在程序用带指针参数的delete运算符撤销对象时，会发生一个情况：系统会只执行基类的析构函数，而不执行派生类的析构函数。 \[例12.3] 基类中有非虚析构函数时的执行情况。为简化程序，只列出最必要的部分。 \[code="C++"]#include using namespace std; class Point //定义基类Point类 { public: Point( ){} //Point类构造函数 ~Point(){cout&lt;&lt;"executing Point destructor"&lt;