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

📄 prog9_02a.cpp

📁 c++最经典的入门书籍
💻 CPP
字号:
// Program 9.2a Overloading a function with const reference parameters
#include <iostream>
using std::cout;
using std::endl;
double larger(double a, double b);
long larger(const long& a, const long& b);

int main() {
  double a_double = 1.5, b_double = 2.5;
  cout << endl;
  cout << "The larger of double values " 
       << a_double << " and " << b_double <<" is " 
       << larger(a_double, b_double) << endl;
 
  int a_int = 15, b_int = 25;
  cout << "The larger of int values "
       << a_int << " and " << b_int <<" is " 
       << larger(static_cast<long>(a_int), static_cast<long>(b_int))
       << endl;
  return 0;
}

// Function to return the larger of two floating point values
double larger(double a, double b) {
  cout << "double larger() called" << endl;
  return a>b ? a : b;
}

// Return the larger of two long references
long larger(const long& a, const long& b) {
  cout << "long ref larger() called" << endl;
  return a>b ? a : b;
}

⌨️ 快捷键说明

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