|
|
|
|
|
by saghm
38 days ago
|
|
> When you write `int& ref = ptr;` you are dereferencing the pointer with `ptr` therefore you have promised that it's valid. Yes, that's exactly the problem. "I promise I didn't make a mistake when reasoning about this code" is tied for worst strategy in the world for preventing bugs, along with every other strategy that doesn't actually prevent bugs. |
|
The real problem is that references are not good enough in C++, so some C++ developers end up using pointers for everything. Rust's references are good enough that you can avoid using pointers most of the time.