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
Reduce avoidable object construction and destruction in C++ class operations and expression evaluation.
How deep it goes
Explain intermediate objects and constructor costs, then show operator fixes; note that compilers may optimize some temporaries.
Examples
Use a Complex class to contrast chained assignment by value with reference return and chained addition with +=.
What you can do after
Build C++ class operators that avoid unnecessary copies while preserving chained assignment and arithmetic behavior.

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 →

Also covered in

What to know first

Related concepts

Questions about temporary object

What is temporary object?

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

Which Manning books explain temporary object?

100 C++ Mistakes and How to Avoid Them and Modern C, Third Edition.

What should I know before learning temporary object?

Manning books that teach temporary object usually introduce compound literal, object and variable-length array first.

What is temporary object a kind of?

Temporary object is a kind of object. A programming-language object is a runtime entity with a type or properties and associated state that participates in computation.

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.