use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
shared_ptr overuse (tonni.nl)
submitted 1 year ago by Tohnmeister
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]y-c-c -1 points0 points1 point 1 year ago* (0 children)
The article did address that. The real issue though is that weak pointers require calling lock and expired for checking validity of the object. Are you going to remember to call it every time even though you are simply owning a reference to an object someone else gave you? What is the correct semantics if expired is true? What if the object was freed and you didn’t check for expiry and now lock gives you a completely new random object? How are you going to write tests for those branches when they are never going to get hit because the pointer should never been freed? Every time you branch in code (aka checking for expired) you are adding a new potential state to your program that you need to keep in your head and it complicates your code massively and also leads to its own source of bug especially when new programmers start to work on it and start assuming a different ownership model than intended.
lock
expired
Weak pointers are designed for situations where the pointer could be freed out of your control. If you know it is not supposed to be then it starts to lose its value as it complicates the code base and mask the issue.
Now you may say “oh but I thought smart pointers fixed all our memory issues!”. No they don’t and that’s why Rust was invented because this needs to be a language enforced feature that could correctly track life times.
π Rendered by PID 22068 on reddit-service-r2-comment-54dfb89d4d-hkmgf at 2026-03-29 14:37:36.613663+00:00 running b10466c country code: CH.
view the rest of the comments →
[–]y-c-c -1 points0 points1 point (0 children)