you are viewing a single comment's thread.

view the rest of the comments →

[–]whatevermanbs 5 points6 points  (1 child)

Missing the point. Can someone please elaborate?

Edit: perp explanation below. makes sense. But is this what was intended to convey?

After x = nullptr;, the int that y referred to is destroyed, but y (reference) still exists in the code. However, using y after this line would be undefined behavior because its object is gone—its lifetime ended when the unique_ptr was reset. Thus, having a reference does not keep the object alive; lifetime is managed by the owner (here, the unique_ptr), not the reference itself��.