https://rentry.org/PPP2_p138

// Code derived from Stroustrup's PPP2 book
// § 5.3.2 Type errors
//  -and beginning on p 138

#include <iostream>

using std::cout;

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

int main()
{
  int x0 = arena(7);          // error: undeclared function
  int x1 = area(7);           // error: wrong number of arguments
  int x2 = area("seven", 2);  // error: 1st argument has a wrong type

  cout << x0 << '\n'  //
       << x1 << '\n'  //
       << x2 << '\n';
}

int area(int length, int width) { return length * width; }

build & run:

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

PrevUpNext

Edit
Pub: 19 Feb 2023 05:46 UTC
Edit: 29 Apr 2023 09:00 UTC
Views: 391