How conversions that creates prvalue are create temporary objects?

85 Views Asked by At

From cppreference

Temporary objects are created .. in the following situations:

  • conversion that creates a prvalue (including T(a,b,c) and T{})

When this can happen? (examples will be appreciated)

What does they mean by "including T(a,b,c) and T{}"?

Do static_cast<T>(e), const_cast<T>(e), dynamic_cast<T>(e) and reinterpret_cast<T>(e) conversions are always evaluate to prvalue?

1

There are 1 best solutions below

3
eerorika On

When this can happen? (examples will be appreciated)

What does they mean by "including T(a,b,c) and T{}"?

"including T(a,b,c) and T{}" means that T(a,b,c) and T{} are examples of cases where temporary objects are created (until C++17).

Do static_cast<T>(e), const_cast<T>(e), dynamic_cast<T>(e) and reinterpret_cast<T>(e) conversions are always evaluate to prvalue?

No. The quoted sentence implies that there are prvalue conversions and non-prvalue conversions, and the latter don't necessarily create temporary objects. If T is a reference type, then the conversion is a glvalue.