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

📄 main.cpp

📁 一本语言类编程书籍
💻 CPP
字号:
// Exercise 12.2 Using a function with a reference parameter in the Integer class - main.cpp
/***********************************************************
 Using the version of compare()with the pass-by-value parameter,
 the copy constructor is called because a copy of the argument
 is passed to the function.
 Using the version with the reference parameter a reference
 to the object is passed to the function so no constructor call
 is necessary.
 You cannot overload a function with a reference parameter with
 a function that has a non-reference parameter because the
 compiler cannot tell which function should be called in any 
 particular instance.
 ***********************************************************/
#include <iostream>
#include "Integer.h"
using std::cout;
using std::endl;

int main() {
  cout << endl << "Create i with the value 10." << endl;
  Integer i(10);
  i.show();
  cout << "Change value  of i to 15." << endl;
  i.setValue(15);
  i.show();
 
  cout << endl << "Create j from object i." << endl;
  Integer j(i);
  j.show();
  cout << "Set value of j to 150 times that of i." << endl;
  j.setValue(150*i.getValue());
  j.show();

  cout << endl << "Create k with the value 789." << endl;
  Integer k(789);
  k.show();
  cout << "Set value of k to sum of i and j values." << endl;
  k.setValue(i.getValue()+j.getValue());
  k.show();

  cout << endl << "Result of comparing i and j is " <<  i.compare(j) << endl;
  cout << endl << "Result of comparing k and j is " <<  k.compare(j) << endl;

  return 0;
}

⌨️ 快捷键说明

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