Value vs. Object

  • A+


When a prvalue expression is evaluated, the standard says that it result in a value. In the case of 5 the expression is a prvalue, and it evaluates to the value 5.

However, when you have a prvalue, mainly an initializer for an object, such as Foo{}. What would the value of this expression be? Would the result be the temporary object created by the prvalue-to-xvalue conversion? This brings on my broader question of the difference between a value and an object.



An object is created by a definition, by a new-expression, when implicitly changing the active member of a union, or when a temporary object is created. An object occupies a region of storage in its period of construction, throughout its lifetime, and in its period of destruction.

Regardless of whether a prvalue has class type like Foo{} or not, as the literal 5, is considered a value and that value is then used to initialize an object if it's really necessary, this is when the value is materialized into an object.


The materialization of a temporary object is generally delayed as long as possible in order to avoid creating unnecessary temporary objects.

Under that same section you'll find a list describing when temporaries are materialized.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: