Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is only partially true. A C++ reference can outlive the object it references. A better argument would be Rust's borrowed pointers, which are statically checked to never point to an invalid object throughout their entire lifetimes.

To talk about lifetimes, you need linear logic in the core language. Merely having destructors is not enough.



This is only partially true. A C++ reference can outlive the object it references.

I didn't mean to imply that it couldn't, just that by using a reference instead of a pointer you are disclaiming responsibility for lifetime management of the referenced item since you can not delete a reference.

C++ being what it is, one can ref = *(new object());, delete &ref;, but the intention you are expressing by using a reference is more hands off in nature. It isn't retargetable, no built-in ability to new\delete, etc.


Manually making sure a reference does not outlive the referenced object (or, at least, that a reference is not used after the object has been destroyed) looks pretty much like "lifetime management" to me. What C++ affords you is merely ownership management.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: