C++中虚析构函数的作用

#include <iostream>
#include <Windows.h>
#include <string.h>
using namespace std;

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

	virtual void DoSomething() { cout << "Do something in class ClxBase!" << endl; };
};

class ClxDerived : public ClxBase
{
public:
	ClxDerived() {};
	~ClxDerived() { cout << "Output from the destructor of class ClxDerived!" << endl; }; 

	void DoSomething() { cout << "Do something in class ClxDerived!" << endl; };
};

void main()
{	
	ClxBase *pTest = new ClxDerived;
	pTest->DoSomething();
	delete pTest;
	system("pause");
}
点击打开链接

原文地址:https://www.cnblogs.com/byfei/p/14104274.html