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

📄 prog16_08.cpp

📁 一本语言类编程书籍
💻 CPP
字号:
// Program 16.8 Destroying objects through a pointer  File: prog16_08.cpp
#include <iostream>
#include "Box.h"                                    // For the Box class
#include "ToughPack.h"                              // For the ToughPack class
#include "Carton.h"                                 // For the Carton class
#include "Can.h"                                    // for the Can class
using std::cout;
using std::endl;

int main() {
  Vessel* pVessels[] = { new Box(40, 30, 20),    new Can(10, 3),
                         new Carton(40, 30, 20), new ToughPack(40, 30, 20) };

  cout << endl;
  for(int i = 0 ; i < sizeof pVessels / sizeof(pVessels[0]) ; i++)
    cout << "Volume is " << pVessels[i]->volume() << endl;

  // Delete the objects from the free store
  for(int i = 0 ; i < sizeof pVessels / sizeof(pVessels[0]) ; i++)
    delete pVessels[i];

  return 0;
}

⌨️ 快捷键说明

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