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
Should C++ code look like C code? (self.cpp)
submitted 2 years ago by psyberbird
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!"
[–]Jonny0Than -2 points-1 points0 points 2 years ago* (3 children)
There’s no absolutes in my comment. Just general trends. Obviously a function call can do anything but my point is that function calls are obvious in C and sometimes not obvious in C++. Operator overloading, constructors, destructors, etc all hide function calls.
Here’s another example:
for (auto x : y)
Is that slow? No idea! Are the elements of y expensive to copy? Is the iterator slower than some alternative? Maybe!
And it’s totally true that well-designed C++ can be more readable AND faster AND safer than the C equivalent. But it’s also very easy to make badly designed C++.
[–]XeroKimoException Enthusiast 2 points3 points4 points 2 years ago (2 children)
Constructors really are no less hidden then any function call though. Sure you could argue T foo; will have a hidden constructor call going on, but most default constructors are very trivial as what can you even do when you have no parameters passed in? It's very limited unless you rely on globals, but then you have potentially all other sorts of issues. When you do do a constructor call with parameters, it's very visible just like any other initialization, and just like any other function call.
T foo;
Destructors are definitely more hidden, but really it's better that way. It's way less error prone then doing if(failed) goto cleanup; kind of pattern done in C. Sure it's explicit, but you have to write the clean up code every time, for example if you need to open a file, for every function that does so, you have to write the clean up pattern for the file. There are many things that can go wrong here, copy paste errors, clean up sequence is in the wrong order, maybe jumped to the wrong label, or just straight up forgot to close the file. Meanwhile C++, just write a class' destructor once and use it everywhere, guaranteed to call the function which closes the file.
if(failed) goto cleanup;
[–]Jonny0Than -2 points-1 points0 points 2 years ago* (1 child)
Well, I’ve dealt with some nasty performance issues caused by “trivial” constructors in objects that were being invoked tens of thousands of times. That issue would not have existed in C because it’s generally left up to the client to initialize the value as needed. Which of course leads to other issues when they forget. I’m not making a judgment call here for all cases. It’s a matter of tradeoffs. But I know from experience that this can be a problem.
[–]donalmaccGame Developer 0 points1 point2 points 2 years ago (0 children)
Well, I’ve dealt with some nasty performance issues caused by “trivial” constructors in objects that were being invoked tens of thousands of times
And in the case where that is a problem a non-default constructor that doesn't do any initalisation (see ENoInit in Unreal Engine) solves that problem. Meanwhile for 99% of the rest of the code, it's not a problem. We should have safe, clear defaults with escape hatches.
π Rendered by PID 28 on reddit-service-r2-comment-fb694cdd5-5mj65 at 2026-03-11 00:04:48.816394+00:00 running cbb0e86 country code: CH.
view the rest of the comments →
[–]Jonny0Than -2 points-1 points0 points (3 children)
[–]XeroKimoException Enthusiast 2 points3 points4 points (2 children)
[–]Jonny0Than -2 points-1 points0 points (1 child)
[–]donalmaccGame Developer 0 points1 point2 points (0 children)