October 2011
Beginner to intermediate
1200 pages
35h 33m
English
The usual C++ practice for passing class objects to a function is to use references. For instance, you would use reference parameters for functions taking objects of the string, ostream, istream, ofstream, and ifstream classes as arguments.
Let’s look at an example that uses the string class and illustrates some different design choices, some of them bad. The general idea is to create a function that adds a given string to each end of another string. Listing 8.7 provides three functions that are intended to do this. However, one of the designs is so flawed that it may cause the program to crash or even not compile.
Listing 8.7. strquote.cpp
// strquote.cpp -- different designs#include <iostream>#include <string> ...
Read now
Unlock full access