⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 v-destructor.cpp

📁 适合初学者学习以及程序员回顾
💻 CPP
字号:
// V-Destructor.cpp

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

//---- 宣告类别 Shape --------
class Shape
{
private:
  int i;
public:
  Shape(): i(7)  
   {cout << "  Shape    建构函数\n";}
  virtual ~Shape()
   {cout << "  Shape    解构函数\n";}
  virtual void Rotate()   
   {cout << "将图回转 \n";}
  virtual void Erase()  
   {cout << "将图清除\n";}
};

//---- 宣告类别 Circle--------
class Circle : public Shape
{
private:
  int r;
public:
  Circle(): r(5)      
    {cout << "  Circle   建构函数\n";}
  Circle(int N): r(N) 
    {cout << "  Circle   建构函数\n";}
  ~Circle()           
    {cout << "  Circle   解构函数\n";}
  void Rotate()  {cout<<"将圆形回转\n";}
  void Erase()   {cout<<"把圆形清除 \n";}
};

//---- 宣告类别 Cylinder--------
class Cylinder : public Circle
{
private:
  int r, h;
public:
  Cylinder(): r(5), h(1)    
     {cout << "  Cylinder 建构函数\n";}
  Cylinder(int M, int N): r(M), h(N)
     {cout << "  Cylinder 建构函数\n";}
  ~Cylinder()         
     {cout << "  Cylinder 解构函数\n";}
  void Rotate(){cout<<"将圆柱形回转\n";}
  void Erase() {cout<<"把圆柱形清除 \n";}
};

// ----主程式---------------------------
main()
{
  cout << "(1) 定义一个 Circle:\n";
  Shape *pS1 = new Circle;
  cout << "(2) 定义一个 Cylinder:\n";
  Shape *pS2 = new Cylinder;
  cout << "(3) 清除 pS1:\n";
  delete pS1;
  cout << "(4) 清除 pS2:\n";
  delete pS2;
}
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -