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

📄 prog16_05.cpp

📁 c++最经典的入门书籍
💻 CPP
字号:
// Program 16.5 Using virtual functions through a reference to the base class
// File: prog16_05.cpp
#include <iostream>
#include "Box.h"                               // For the Box class
#include "ToughPack.h"                         // For the ToughPack class
#include "Carton.h"                            // For the Carton class
using std::cout;
using std::endl;

void showVolume(const Box& rBox);              // Prototype for global function

int main() {
  Box myBox(20.0, 30.0, 40.0);                 // Declare a base box
  ToughPack hardcase(20.0, 30.0, 40.0);        // Declare derived box - same size
  Carton aCarton(20.0, 30.0, 40.0);            // A different kind of derived box

  cout << endl;
  showVolume(myBox);                           // Display volume of base box
  showVolume(hardcase);                        // Display volume of derived box
  showVolume(aCarton);                         // Display volume of derived box

  // Lines deleted

  return 0;
}

// Global function to display the volume of a box
void showVolume(const Box& rBox) {
  rBox.showVolume();
}

⌨️ 快捷键说明

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