While searching for some loosely related stuff I bumped into this quote:
And a reference can outlive an object and be used to refer to a new object created at the same address.
From this answer.
Now, I've always known and worked by references being immutable, initialized once and all that. Reading the above quote, by someone likely more experienced than I am, got me wondering if I'm missing something.
Was that sentence meant to be for the sake of completeness but practically inapplicable?
Is there some pattern or circumstance where people would go through the pain of landing a new object of the same type in a specific memory address just to to do a switcheroo for a reference? (which seems supremely dangerous to me, not to mention convoluted at the best of times).
I think this could only make sense in the context of a placement new. If the object the reference points to was created with placement new, it should be possible to destroy the object and create a new object in the same spot with placement new again. I don't see any immediate reason not to use a pointer instead at the moment though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With