CPP虚析构函数

2023-12-24 22:38:00
#include<iostream>
using namespace std;

class base
{
	public:
		base(){};
		virtual ~base(){};
};

// 在类声明中声明纯虚析构函数
//base::~base() {}

class father: public base
{
	public:
		~father(){
			cout << "father" << endl;
		}
};

int main()
{
	base* a;
	a=new father();
	
	delete a;
	
}

#include<iostream>
using namespace std;

class base
{
	public:
		base(){};
		~base(){};
};

// 在类声明中声明纯虚析构函数
//base::~base() {}

class father: public base
{
	public:
		~father(){
			cout << "father" << endl;
		}
};

int main()
{
	base* a;
	a=new father();
	
	delete a;
	
}

文章来源:https://blog.csdn.net/m0_73687532/article/details/135187202
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。