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

📄 ex7_15.cpp

📁 Visual C++ 2005的源代码
💻 CPP
字号:
// Ex7_15.cpp : main project file.
// Using the Box reference class type

#include "stdafx.h"

using namespace System;

ref class Box  
{
  public:
    // No-arg constructor supplying default field values
    Box(): Length(1.0), Width(1.0), Height(1.0)
   {
     Console::WriteLine(L"No-arg constructor called.");
   }
    // Constructor definition using an initialisation list
    Box(double lv, double bv, double hv):
                             Length(lv), Width(bv), Height(hv)
   {
     Console::WriteLine(L"Constructor called.");
   }

   // Function to calculate the volume of a box
   double Volume()
   {
     return Length*Width*Height;
   }

  private:
    double Length;                     // Length of a box in inches
    double Width;                      // Width of a box in inches
    double Height;                     // Height of a box in inches
};

int main(array<System::String ^> ^args)
{
  Box^ aBox;                           // Handle of type Box^
  Box^ newBox = gcnew Box(10, 15, 20);
  aBox = gcnew Box;                    // Initialize with default Box
  Console::WriteLine(L"Default box volume is {0}", aBox->Volume());
  Console::WriteLine(L"New box volume is {0}", newBox->Volume());
  return 0;
}

⌨️ 快捷键说明

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