contents.cpp

来自「一本语言类编程书籍」· C++ 代码 · 共 26 行

CPP
26
字号
// Contents.cpp
#include "contents.h"
#include <cstring>
#include <iostream>
using std::cout;
using std::endl;

// Constructor
Contents::Contents(const char* pStr, double weight, double vol):
                                     unitweight(weight), volume(vol) {
  pName = new char[strlen(pStr)+1];
  std::strcpy(pName, pStr);
  cout << "Contents constructor" << endl;    
}

// Destructor
Contents::~Contents() {
  delete[] pName;
  cout << "Contents destructor" << endl;
}

// "Get Contents weight" function
double Contents::getWeight() const { 
  return volume*unitweight; 
}

⌨️ 快捷键说明

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