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

Passing parameters by reference is certainly not always safe. You can, for example, pass a reference to a deref'ed unique_ptr into a function call, while the function call does something that clears the unique_ptr.

If you want to avoid objects containing references (or raw pointers), then you have to avoid using lots of standard library stuff --- `string_view`, C++20 `span`, or even STL iterators.



Now you are talking about pointers.


There isn't much difference between references and pointers. That is the problem.


A reference only ever points at one thing, from birth to death, and it always points at something.


No, it is entirely possible to delete the underlying object so a reference is left dangling. See https://github.com/isocpp/CppCoreGuidelines/issues/1038 for example.




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

Search: