https://rentry.org/PPP2_p140

// Code derived from Stroustrup's PPP2 book
// § 5.4 Link-time errors
//  -and beginning on p 140

#include <cstdlib>
#include <iostream>

using std::cerr;
using std::cout;

// calculate area of a rectangle
int area(int length, int width);

int main()
{
  int x = area(2, 3);

  cout << x << '\n';
}

// “our” area()
int area(int length, int width) { return length * width; }

// not “our” area()
double area(double x, double y)
{
  /* . . . */

  return 0.0;  // stub (ie, 'a temp placeholder/value/etc'; here as a return)
}

// not “our” area()
int area(int x, int y, char unit)
{
  /* . . . */

  return 0;  // stub (ie, 'a temp placeholder/value/etc'; here as a return)
}

build & run:

g++ -std=c++20 -O2 -Wall -pedantic ./ch_05/main_p140.cpp && ./a.out

PrevUpNext

Edit
Pub: 20 Feb 2023 11:11 UTC
Edit: 29 Apr 2023 09:04 UTC
Views: 587