3 ms·
Lifetimes. In C++ you don't have to think about ownership to make the compiler happy; you only have to worry about that stuff if you want your program not to cr
by firethief 7y ago
Lifetimes. In C++ you don't have to think about ownership to make the compiler happy; you only have to worry about that stuff if you want your program not to crash.
- codesushi42 7y agoCan you give an example? Smart pointers make you consider ownership. Or does Rust account for more than that?
- firethief 7y agoRust's ownership model tracks the safety of borrows at compile time in ways C++ can't. You can derive a reference from another reference, and the compiler won't let you do anything to the original object that would leave the derived reference dangling. In C++ there are two different conventions for that: use plain old pointers to represent the borrows, and be careful they don't outlive the owning `unique_ptr`; or use `shared_ptr` to do the bookkeeping at runtime (also available in Rust, as Rc/Arc).
- codesushi42 7y agoGot it, thanks for the explanation. So C++ programmers are able to subvert the upfront complexity by ignoring C++ 11 features then, going straight to raw pointers.
- unrealhoang 7y agoThat's exactly why I use Rust, I can not be sure when I get enough confident with C++ to not make my program crash in unexpected ways.