liveBook · Manning

Temporary object

A temporary object is an unnamed object created for an intermediate expression or initialization whose lifetime is limited by language rules.

How 2 Manning books explain it

100 C++ Mistakes and How to Avoid Them

A temporary object is an unnamed object created for an intermediate expression or value and typically given a limited lifetime.

How it is used
Uses temporary objects to identify avoidable construction and destruction costs in class operations and arithmetic expressions.
How deep it goes
Explains intermediate results, constructor and destructor costs, and operator remedies, but does not develop detailed lifetime rules.
Examples
Demonstrates Complex assignment, chained addition, operator+=, and incremental accumulation.
What you can do after
Diagnose unnecessary temporaries and reduce them by returning references and applying compound assignment where appropriate.

Read how 100 C++ Mistakes and How to Avoid Them explains temporary object →

Modern C, Third Edition

A temporary object is an unnamed C object created for an intermediate expression or initialization and given automatic temporary lifetime.

How it is used
Uses unnamed intermediate objects to explain automatic storage and compile-time type checking.
How deep it goes
Explains implicit creation and optimization, but stops short of a complete lifetime model for every temporary-expression context.
Examples
Demonstrates a returned struct accessed through mem().ory[0] and a compound literal used for macro argument checking.
What you can do after
Evaluate C expressions that create unnamed objects and recognize compound-literal techniques for assignment-compatibility checks.

Read how Modern C, Third Edition explains temporary object →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.