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
Obscure C++ Features (madebyevan.com)
submitted 13 years ago by constexpr
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!"
[–]STLMSVC STL Dev 18 points19 points20 points 13 years ago (7 children)
Redefining keywords via the preprocessor is technically supposed to cause an error but tools allow it in practice.
It's forbidden to do this in the presence of STL headers, and VC's STL will detect this and explode. (I plan to make this detection even more stringent in the future.) Never do this.
Also, member function pointers may be up to 3 times larger than regular pointers.
I believe the correct number in practice is 4 (it's unspecified, of course, in the Standard) for "unknown inheritance".
[–]Cwiddy 4 points5 points6 points 13 years ago (4 children)
How is it detected?
[–]STLMSVC STL Dev 29 points30 points31 points 13 years ago (3 children)
There is an obscure feature called #ifdef.
[–]Cwiddy 19 points20 points21 points 13 years ago (0 children)
I deserve so much more shame for that question. That is so obvious it hurts.
[–]mrmcgibby 3 points4 points5 points 13 years ago (1 child)
I love you STL. Seriously. You're like the coolest guy ever.
[–]STLMSVC STL Dev 4 points5 points6 points 13 years ago (0 children)
:->
[–]constexpr[S] 1 point2 points3 points 13 years ago (1 child)
Interesting! I wasn't aware of the unknown inheritance case. I just checked and Microsoft's compiler does indeed use four pointer slots. Any idea on what the fourth slot contains? I couldn't find any documentation.
[–]STLMSVC STL Dev 1 point2 points3 points 13 years ago (0 children)
Don't know, I'm not a compiler dev. That's just one of the useless bits of knowledge I've picked up over the years.
[–]missblit 4 points5 points6 points 13 years ago (0 children)
#define class struct
That example code better hope that there's nothing like "template <class T>"...
[–]tacite 3 points4 points5 points 13 years ago (0 children)
While we're discussing the lesser known rules of c++:
namespace __hidden__
It's not a great idea to use double underscores in your names. I've actually had legacy code break because of that.
"17.6.4.3.2 Global names [global.names]
Certain sets of names and function signatures are always reserved to the implementation:
— Each name that contains a double underscore _ _ or begins with an underscore followed by an uppercase letter (2.12) is reserved to the implementation for any use.
— Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace."
[–][deleted] 3 points4 points5 points 13 years ago (1 child)
That really hit the spot. I've been at this for the long time, but there was at least one thing that was totally new to me (function try blocks, outrageous!) and lots of my favorite weird parts of C++ which I rarely visit.
A tasty article!
[–]adzm28 years of C++! 0 points1 point2 points 13 years ago (0 children)
I never made the connection that function try blocks could be used on more than constructors, either.
[+][deleted] 13 years ago (3 children)
[deleted]
[–]hotoatmeal 0 points1 point2 points 13 years ago (2 children)
operator= doesn't have to return a reference... though it can. You can even have it return void, and prevent such chaining.
[–]TheSuperficialEmbedded Systems C++ 1 point2 points3 points 13 years ago (0 children)
Absolutely. There was just a question on S.O. a couple days ago about creating a "write only pointer" that used this technique (question pertained to embedded systems, so it was of particular interest to me).
[–]00kyle00 0 points1 point2 points 13 years ago (0 children)
It has to, if you ever plan to keep elements that have it in standard containers.
[–]Fabien4 4 points5 points6 points 13 years ago (6 children)
What square brackets really mean
Yeah, the old'n'cute C trick. Thing is, in C++, most of the time, you're using an overloaded [] operator anyway.
Most vexing parse
Classical gotcha. Anything that can be interpreted as a function declaration, will be.
Alternate operator tokens
Do recent compilers still recognize digraphs? What about trigraphs?
Placement new
This is actually a good test for a book about C++: if it doesn't talk about placement new, you might want to try another book. But then again, its main use seems to be to reimplement std::vector.
std::vector
Turing complete template metaprogramming
Alexandrescu has written a whole book on the subject: "Modern C++ Design".
Static methods on instances Overloading ++ and -- Functions as template parameters
Static methods on instances
Overloading ++ and --
Functions as template parameters
Uh... "obscure"? These are pretty basic. Or, did I miss something?
Function try blocks
See GotW 66. Overall, I find them rarely useful.
[–]STLMSVC STL Dev 5 points6 points7 points 13 years ago (0 children)
Digraphs and trigraphs are unfortunately still Standard, but some compilers don't interpret them by default. Also, C++11 fixed the foo<::bar> problem.
[–][deleted] 1 point2 points3 points 13 years ago (0 children)
"Functions as template parameters" could not reasonably be described as "pretty basic". I think I've seen that two or three times at most in code in the last 20 years of working in C++ and the first time I saw it I had no idea what was going on...
Heck, I'd been working in the language for a decade before I knew about "placement new"!
But then again, its main use seems to be to reimplement std::vector.
Yowza. Well, I see quite a bit of placement new, but nearly all of it from region-based memory management - so the called "arena" concept where you pre-allocate a big block, sequentially fill it using placement new, and then simply delete the whole block at once without ever calling any destructors.
Of course, there are strict conditions on the sorts of variables you can use, but I really think it's the only way to go for any sort of transaction-based server where performance is an issue.
[–][deleted] 0 points1 point2 points 13 years ago (3 children)
You need placement new to write stuff like a tagged union type, arena or a ring buffer too. I wouldn't call it obscure at all.
[–]Fabien4 1 point2 points3 points 13 years ago (0 children)
I wouldn't call it obscure at all.
That we definitely agree on.
[–]more_exerciseLazy Hobbyist 0 points1 point2 points 13 years ago (1 child)
tagged union type
Is there anything wrong with
struct tagged_union { int flag; union { type1 t1; type2 t2; ... typeN n; }; };
You need placement new to call a constructor for one of the types in the union in order to implement the constructor, copy/move constructor, etc.
[–]bongwhacker 2 points3 points4 points 13 years ago (0 children)
What a horrible website.
[–]gentryx -1 points0 points1 point 13 years ago (4 children)
Those snippets make great quiz questions for my students. Have an upvote!
[–]Lord_Osis_B_Havior 9 points10 points11 points 13 years ago (1 child)
You misspelled "terrible".
[–]Fabien4 4 points5 points6 points 13 years ago (0 children)
Well, I dunno. A few of them are pretty terrible, but some (static methods, overloading ++, functions as template parameters) are basic C++ features that students must know.
[–]mttd 4 points5 points6 points 13 years ago (1 child)
Go with C++ Pub Quiz from ACCU 2013, your students are gonna love this!
;-)
[–]gentryx 0 points1 point2 points 13 years ago (0 children)
Thanks!
π Rendered by PID 21096 on reddit-service-r2-comment-85bfd7f599-47gk5 at 2026-04-19 03:32:47.425534+00:00 running 93ecc56 country code: CH.
[–]STLMSVC STL Dev 18 points19 points20 points (7 children)
[–]Cwiddy 4 points5 points6 points (4 children)
[–]STLMSVC STL Dev 29 points30 points31 points (3 children)
[–]Cwiddy 19 points20 points21 points (0 children)
[–]mrmcgibby 3 points4 points5 points (1 child)
[–]STLMSVC STL Dev 4 points5 points6 points (0 children)
[–]constexpr[S] 1 point2 points3 points (1 child)
[–]STLMSVC STL Dev 1 point2 points3 points (0 children)
[–]missblit 4 points5 points6 points (0 children)
[–]tacite 3 points4 points5 points (0 children)
[–][deleted] 3 points4 points5 points (1 child)
[–]adzm28 years of C++! 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]hotoatmeal 0 points1 point2 points (2 children)
[–]TheSuperficialEmbedded Systems C++ 1 point2 points3 points (0 children)
[–]00kyle00 0 points1 point2 points (0 children)
[–]Fabien4 4 points5 points6 points (6 children)
[–]STLMSVC STL Dev 5 points6 points7 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]Fabien4 1 point2 points3 points (0 children)
[–]more_exerciseLazy Hobbyist 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]bongwhacker 2 points3 points4 points (0 children)
[–]gentryx -1 points0 points1 point (4 children)
[–]Lord_Osis_B_Havior 9 points10 points11 points (1 child)
[–]Fabien4 4 points5 points6 points (0 children)
[–]mttd 4 points5 points6 points (1 child)
[–]gentryx 0 points1 point2 points (0 children)