(ref.doc)cr59-38

Prev: cr59-20 Up: cppR 5/9

pp 38-41
Using C++ effectively
Efficiency and the real world
What you do when return-by-value is too expensive, but
return-by-reference is just plain wrong?
by Scott Meyers (Note:
 Meyers)

Don't try to return a reference when you must return an object.

Five different ways:

- Use a non-operator function, and pass in an additional parameter
  specifying where the result of the function is to be stored.
- Augment a binary operator like operator+ with its corresponding
  assignment operator, for example operator+=.
- Return a pointer to an object allocated on the heap within the
  called function.
- Replace the expensive-to-copy class with a handle class.
- Add a special constructor to the class being returned by value so
  that function can "return" constructor arguments instead of a
  complete object.

automatically generated by info2www version 1.2.2.8