Is it possible to do so? Will the pointer be beaten?
void foo() { SomeType *pObj = nullptr; pObj = &(SomeType(arg1, arg2)); ... // *pObj ? }
Is it possible to do so? Will the pointer be beaten?
void foo() { SomeType *pObj = nullptr; pObj = &(SomeType(arg1, arg2)); ... // *pObj ? }
It is impossible. Only the constant lvalue-link and the rvalue-link prolong the lifespan. Here it is possible:
void foo() { const SomeType& obj = SomeType(arg1, arg2); ... // obj ! }
and so:
void foo() { SomeType&& obj = SomeType(arg1, arg2); ... // obj ! }
Proof of the above can be found in the C ++ standard (12.2 / 5):
There are two contexts in which you can destroy the ...
The second context is when a reference is bound to a temporary. There are no limits to this subject.
Source: https://ru.stackoverflow.com/questions/416520/
All Articles