O'Reilly logo

C++ Primer Plus by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reference Properties and Oddities

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required