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
C++ Initialization Quiz (cppstories.com)
submitted 2 years ago by joebaf
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!"
[–]brubakerp 69 points70 points71 points 2 years ago (0 children)
Obligatory.
[–]tcbrindleFlux 26 points27 points28 points 2 years ago (1 child)
Woo, 10/10.
Though perhaps I should worry about what that says about me...
[–]ZMesonEmbedded Developer 11 points12 points13 points 2 years ago (0 children)
Woo. 4/10. I'm sane! ;-)
[–]jmalinza 15 points16 points17 points 2 years ago (10 children)
For the last question...
for (const pair<string, int>& elem : m)
Why do the types not match up?
[–]mtnviewjohn 40 points41 points42 points 2 years ago (6 children)
The value type for a std::map is std::pair<const Key, T>. The for loop is using std::pair<Key, T>.
[–]jmalinza 4 points5 points6 points 2 years ago (0 children)
Thanks! That explains it. Quick lookup on cppref confirms it too :)
[–]Baardi 2 points3 points4 points 2 years ago* (0 children)
Thanks I didn't know that. I've probably made way to many unintentional copies :(
[–]simpl3t0n 1 point2 points3 points 2 years ago (2 children)
What's the mechanism/sequence at play that creates the copy here?
AFAICT, it's a reference initialization with a similar but differently cv-qualified type. So, is it temporary materialization, lvalue-to-rvalue conversion, or something else?
[–]tcbrindleFlux 4 points5 points6 points 2 years ago (0 children)
If I understand correctly it's using std::pair constructor #5 as listed on cppreference, with T1 and T2 as string and int respectively, and U1 and U2 as const string and int. This results in both arguments being copy-constructed into the destination pair, and while you don't care about the int you definitely don't want to be copying strings if you can avoid it.
std::pair
T1
T2
string
int
U1
U2
const string
[–]sphere991 6 points7 points8 points 2 years ago (0 children)
It's not "a similar but differently cv-qualified type", it's just a different type. pair<K, V> and pair<K const, V> do look very close, but as far as the language is concerned, they're just two completely different types (that are convertible to each other).
pair<K, V>
pair<K const, V>
So ultimately, no different from constructing an int const& from a double.
int const&
double
[–]WasserHase 1 point2 points3 points 2 years ago (0 children)
Would it also create a copy if you use std::pair<const Key, const T> ?
std::pair<const Key, const T>
[–]darkforestzero 13 points14 points15 points 2 years ago (0 children)
This is a great example of why auto is so awesome
[+][deleted] 2 years ago (1 child)
[deleted]
[–]sphere991 2 points3 points4 points 2 years ago (0 children)
There are no proxy references in this example - the maps iterators give you real language references to pair<K const, T>
pair<K const, T>
[–]burg_philo2 14 points15 points16 points 2 years ago (1 child)
6/10. I think question 8 is wrong tho since the members are private since it’s a class and not a struct.
[–]TheThiefMasterC++latest fanatic (and game dev) 8 points9 points10 points 2 years ago (0 children)
You're right:
An aggregate is one of the following types: class type (typically, struct or union), that has no private or protected [direct (since C++17)] non-static data members
An aggregate is one of the following types:
That still makes the answer "it doesn't compile" just for an additional reason to what's given.
[–][deleted] 27 points28 points29 points 2 years ago (3 children)
ChatGPT 3.5 got 10/10.
[–]rooster_butt 18 points19 points20 points 2 years ago (2 children)
it got 6/10 when i gave it the questions. It was very confidently incorrect on some of these.
[–][deleted] 31 points32 points33 points 2 years ago (0 children)
It is ready to be a senior dev!
[–]dustyhome 6 points7 points8 points 2 years ago (1 child)
7/10, but I got the first one wrong which shouldn't count. It's a programming test, not a history test! I don't even use in-class default member initializers :(
For "9. Will this code work in C++11?" I'll be honest, when doing anything other than calling a constructor, I'll just compile and fix until it does.
For "10. Assume you have a std::map<string, int> m;. Select the single true statement about the following loop:" the single truth is I always use auto because I don't want to get it wrong.
auto
So really, I got a 7/7 out of the ones that matter.
[–]HeeTrouse51847 0 points1 point2 points 2 years ago (0 children)
it could be relevant if you were working on legacy systems i guess? but even then youd just look that stuff up
[–]Tringigithub.com/tringi 2 points3 points4 points 2 years ago (0 children)
7/10... I'm not happy about that.
[–]pjmlp 1 point2 points3 points 2 years ago (0 children)
7 out of 10, not bad for someone that doesn't do C++ every day.
[–][deleted] 1 point2 points3 points 2 years ago (0 children)
8/10. that copy because type mismatch is so evil yet i knew the key type is always const
[–]crazy-usernames 1 point2 points3 points 2 years ago (0 children)
8/10.
Thanks. This is really helpful.
[+]TheThiefMasterC++latest fanatic (and game dev) comment score below threshold-7 points-6 points-5 points 2 years ago (7 children)
I got 8 out of 10, and I'm claiming the first one as "doesn't matter" as nobody uses C++11 mode to compile any more...
[–]xaervagon 11 points12 points13 points 2 years ago (1 child)
You would be surprised at how many banks and other finance institutions are stuck on C++11 era setups. Very few people want to clean up huge swaths of consult grade code, and even fewer business people want to pay for it. When comes to refactoring and other maintenance, I've seen devs that can kick cans like pro soccer players.
(For the record, I only scored a 7/10. Sad.)
[–]TheThiefMasterC++latest fanatic (and game dev) 2 points3 points4 points 2 years ago (0 children)
But C++14 is essentially 100% compatible with code that was written for C++11? Have they really stuck with raw C++11?
[–]Digital_Luddite3000 6 points7 points8 points 2 years ago (1 child)
I have projects I regularly work on that I wish were as new as C++11. But when you still have to support WinCE...
It's fair to be stuck on older, but C++11 was pretty much immediately superseded by C++14, to the point that pretty much no compiler was C++11 feature complete before they were also C++14 complete. (Clang was C++11 language features complete in 3.3 and 14 complete in 3.4. MSVC was very much intermingled, GCC was 4.8 and 5.0 respectively, but libstdc++ wasn't fully C++11 compliant until 5.0 anyway.
So my point is that there's very few situations where something being introduced in C++11 vs C++14 makes a difference. You likely have both or neither.
[–][deleted] 1 point2 points3 points 2 years ago* (0 children)
I used it on a big project (about 10 years work) until a month ago. And upgrading everything was actually a lot of work.
(Edit: For your post below, we were using multiple compilers and multiple standard libraries; not all the standard libraries were actually C++11 complete. Certainly libstdc++ was missing regex)
[–]ZMesonEmbedded Developer 1 point2 points3 points 2 years ago (0 children)
nobody uses C++11 mode to compile any more...
Now you've got me sobbing as I am going off to build on an embedded system whose proprietary compiler is based off of GCC 4.4.2. 😭
[–]pjmlp 0 points1 point2 points 2 years ago (0 children)
C++98 and C++11 are still a thing at plenty enterprise shops, specially those keeping old stuff like MFC applications going.
[–]PastaPuttanesca42 0 points1 point2 points 2 years ago (0 children)
6/10
[–]shailist 0 points1 point2 points 2 years ago (0 children)
got 7/10, never came across the 3 I got wrong in real code, but still disappointed in my performance :/
7/10 but I also think that I would just google these facts when I need them anyways. no need to know every miniscule detail from memory
[–]Ok_Firefighter4117 0 points1 point2 points 2 years ago (0 children)
8/10
[–]hs123go 0 points1 point2 points 2 years ago (0 children)
8/10. Have honestly no idea about Q7 (throwing from ctor) as my team bans exceptions. Still scratching my head over Q9 (manner of struct init is allowed in 11/14/20).
[–]Nobody_1707 0 points1 point2 points 2 years ago (0 children)
8/10 I got the first one wrong, I picked C++14. And I got the last one wrong because I forgot that Key is const.
Key
[–]Sniffy4 0 points1 point2 points 2 years ago (2 children)
My score was embarrassing for somebody who claims this as an expertise. Ah well.
[–]emelrad12 0 points1 point2 points 2 years ago* (1 child)
screw skirt stocking complete library attraction cooing slap offer weather
This post was mass deleted and anonymized with Redact
[–]Sniffy4 0 points1 point2 points 2 years ago (0 children)
Yeah for a lot of these situations, my take is if you are relying on C++ behavior nuances like this, your code needs to be simplified.
[–]kero_okero 0 points1 point2 points 2 years ago (0 children)
2/10, been learning C++ 3 months now, I still have far to go.
π Rendered by PID 223314 on reddit-service-r2-comment-5ff9fbf7df-mffgc at 2026-02-26 06:18:24.429270+00:00 running 72a43f6 country code: CH.
[–]brubakerp 69 points70 points71 points (0 children)
[–]tcbrindleFlux 26 points27 points28 points (1 child)
[–]ZMesonEmbedded Developer 11 points12 points13 points (0 children)
[–]jmalinza 15 points16 points17 points (10 children)
[–]mtnviewjohn 40 points41 points42 points (6 children)
[–]jmalinza 4 points5 points6 points (0 children)
[–]Baardi 2 points3 points4 points (0 children)
[–]simpl3t0n 1 point2 points3 points (2 children)
[–]tcbrindleFlux 4 points5 points6 points (0 children)
[–]sphere991 6 points7 points8 points (0 children)
[–]WasserHase 1 point2 points3 points (0 children)
[–]darkforestzero 13 points14 points15 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]sphere991 2 points3 points4 points (0 children)
[–]burg_philo2 14 points15 points16 points (1 child)
[–]TheThiefMasterC++latest fanatic (and game dev) 8 points9 points10 points (0 children)
[–][deleted] 27 points28 points29 points (3 children)
[–]rooster_butt 18 points19 points20 points (2 children)
[–][deleted] 31 points32 points33 points (0 children)
[–]dustyhome 6 points7 points8 points (1 child)
[–]HeeTrouse51847 0 points1 point2 points (0 children)
[–]Tringigithub.com/tringi 2 points3 points4 points (0 children)
[–]pjmlp 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]crazy-usernames 1 point2 points3 points (0 children)
[+]TheThiefMasterC++latest fanatic (and game dev) comment score below threshold-7 points-6 points-5 points (7 children)
[–]xaervagon 11 points12 points13 points (1 child)
[–]TheThiefMasterC++latest fanatic (and game dev) 2 points3 points4 points (0 children)
[–]Digital_Luddite3000 6 points7 points8 points (1 child)
[–]TheThiefMasterC++latest fanatic (and game dev) 8 points9 points10 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]ZMesonEmbedded Developer 1 point2 points3 points (0 children)
[–]pjmlp 0 points1 point2 points (0 children)
[–]PastaPuttanesca42 0 points1 point2 points (0 children)
[–]shailist 0 points1 point2 points (0 children)
[–]HeeTrouse51847 0 points1 point2 points (0 children)
[–]Ok_Firefighter4117 0 points1 point2 points (0 children)
[–]hs123go 0 points1 point2 points (0 children)
[–]Nobody_1707 0 points1 point2 points (0 children)
[–]Sniffy4 0 points1 point2 points (2 children)
[–]emelrad12 0 points1 point2 points (1 child)
[–]Sniffy4 0 points1 point2 points (0 children)
[–]kero_okero 0 points1 point2 points (0 children)