Using Returned Objects in Client Code

C++ functions can return built-in values, pointers, references, and objects. They cannot return arrays, but returning pointers allows you to simulate returning arrays. Built-in values can be used as rvalues only. Other return types (pointers, references, and objects) can be used as lvalues. This opens the door to quite interesting idioms in the source code. These idioms contribute to the expressiveness of C++ programs but sometimes make the source code more difficult to understand.

The material in this section can be easily skipped in the first reading, even though the programming idioms I am discussing here are quite common.

Returning Pointers and References

I will start with the discussion of simple (noncomposite) ...

Get Core C++ A Software Engineering Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.