Home Segments Index Top Previous Next

156: Sidetrip

In the program shown in Segment 155, C++ copies the box_car and tank_car objects as those objects are passed to their volume functions. In this respect, passing a class object is just like passing an ordinary integer or floating-point argument. Such copying is to be expected, because C++ is a call-by-value language, but such copying is not necessarily desirable, especially when class objects are large.

In the hardcopy version of this book, you learn about member functions and you learn that C++ passes one class object to each member function without copying. In the hardcopy version of this book, you learn that it is possible to arrange for C++ to prevent you from inadvertently writing a function that copies a class-object argument.