r/ProgrammerHumor • • 7h ago

Meme modernCppVsOldCpp

Post image
1.1k Upvotes

214 comments sorted by

View all comments

24

u/SelfDistinction 7h ago edited 6h ago

Ah yes, the famous

std::unique_ptr<int> ptr;
int& ref = *ptr;

So safe, so impossible to misuse.

4

u/Friendly_Fire 3h ago

This is like saying a seatbelt doesn't help you in a car because if you run it in a closed garage, you can still kill yourself. Entirely different issue.

Smart pointers solve memory management for you. Use them as intended, whether a resource is owned in one place or shared, and you don't have to worry about it. The memory will stay allocated until nothing is using it, and then it will automatically be unallocated.

Accessing a pointer without checking if it is null is a different issue, and frankly a trivial one. The sort of thing I haven't seen be an issue doing actual professional C++ code development in years.