适合初学者学习以及程序员回顾
源代码在线查看: v-destructor.cpp
// V-Destructor.cpp
#include
using std::cin;
using std::cout;
using std::endl;
//---- 宣告类别 Shape --------
class Shape
{
private:
int i;
public:
Shape(): i(7)
{cout virtual ~Shape()
{cout virtual void Rotate()
{cout virtual void Erase()
{cout };
//---- 宣告类别 Circle--------
class Circle : public Shape
{
private:
int r;
public:
Circle(): r(5)
{cout Circle(int N): r(N)
{cout ~Circle()
{cout void Rotate() {cout void Erase() {cout };
//---- 宣告类别 Cylinder--------
class Cylinder : public Circle
{
private:
int r, h;
public:
Cylinder(): r(5), h(1)
{cout Cylinder(int M, int N): r(M), h(N)
{cout ~Cylinder()
{cout void Rotate(){cout void Erase() {cout };
// ----主程式---------------------------
main()
{
cout Shape *pS1 = new Circle;
cout Shape *pS2 = new Cylinder;
cout delete pS1;
cout delete pS2;
}