References vs Pointers

6 months ago by monica_b1998 to c/cpp

References vs Pointers in Modern C++: A complete guide for beginners and intermediate developers. Learn when to use T& and when T* is still necessary.
username_1 5 points 6 months ago
path: 0 23174272, hotness: undefined, score: 5, children: 1
scratchee 1 point 6 months ago

Yeah. References feel like they were originally made to be safer but any safety the could have provided got sacrificed to the compiler for a little more speed, leaving them more dangerous than pointers with the illusion of safety.

That said, compilers are starting to get support for more hardening options now that c/c++ has to care about memory safety, I imagine this might be partially covered by that eventually (eg crash when assigning null to a reference, there's realistically no saving dangling references though)

path: 0 23174272 23181151, hotness: undefined, score: 1, children: 0
cpp
cpp

@programming.dev

login for more options
2381
416
44

The center for all discussion and news regarding C++.

Rules

  • Respect instance rules.
  • Don't be a jerk.
  • Please keep all posts related to C++.

go to feed...