Consideration of the case when copying is not applied (pre C ++ 17).
From cppreference (again, suppose C ++ 14):
Temporary objects are created in the following situations:
- prvalue link binding
- returns value from function
- which creates prvalue
- lambda expression
- copy requiring initializer conversion
- list-initialization, which builds std :: initializer_list
- initialization reference to another, but convertible type or to a bit.
All cases, except the first, seem insignificant, the first, apparently, means a link to a link in the C ++ style ( int &&x = 5; BTW. I do not understand in this case the statement that temporary files are destroyed at the end of a fully functional file, expression ..., object 5 refers to, it seems, is not destroyed at the end of the instruction).
So, as I understand it, the concept of a temporary object includes only those who are guaranteed to be stored (which does not correspond to my situation due to a possible exception). I'm right? Or what am I misunderstanding here?
By the way, is there any difference between MyClass() and 4 in int x = 4; (or 2 + 2 in int x = 2 + 2; )? For example, maybe I'm wrong, and the first one refers to a temporary object, and the other two do not ...
c ++ c ++ 14 temporary
ledonter
source share