October 2011
Beginner to intermediate
1200 pages
35h 33m
English
Using reference arguments has several twists you need to know about. First, consider Listing 8.5. It uses two functions to cube an argument. One takes a type double argument, and the other takes a reference to double. The actual code for cubing is purposefully a bit odd to illustrate a point.
Listing 8.5. cubes.cpp
// cubes.cpp -- regular and reference arguments#include <iostream>double cube(double a);double refcube(double &ra);int main (){ using namespace std; double x = 3.0; cout << cube(x); cout << " = cube of " << x << endl; cout << refcube(x); cout << " = cube of " << x << endl; return 0;}double cube(double a){ a *= a * a; return a;}double refcube(double &ra){ ra *= ra * ra; ...
Read now
Unlock full access