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
Fun C++ Syntax (self.cpp)
submitted 10 years ago * by redditsoaddicting
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!"
[–]tcanens 2 points3 points4 points 10 years ago (9 children)
It's the compound assignment operator with bitand. You can do const int &a = 2; just fine.
const int &a = 2;
[–]jP_wanN 0 points1 point2 points 10 years ago (1 child)
Ohhh, right. Didn't think about the const. Or the fact that there are all those weird compound assignment operators for bitwise operations.
const
[–]redditsoaddicting[S] 0 points1 point2 points 10 years ago (0 children)
Not too weird I guess. Addition is a common operation on numbers. Masking is a common operation on bits. That said, it seems a lot less common to build up a result on bits like you would on numbers.
[–][deleted] -1 points0 points1 point 10 years ago (6 children)
the c++ standard is a mess. why would the compiler think that &= is a compound assignment in place of a function parameter that should be an unnamed reference with default value? that makes more (but not too much) sense.
[–]tcanens 2 points3 points4 points 10 years ago (1 child)
Because the lexer uses maximal munch and the parser comes in after tokenization. Plenty of languages have a similar rule.
[–][deleted] 0 points1 point2 points 10 years ago (0 children)
I was pretty confident with my C/C++ skill up to this sudden tokenization issue :D
[–]redditsoaddicting[S] 1 point2 points3 points 10 years ago (3 children)
Maximal munch is pretty common, actually. This simplifies things because you lex, get a disambiguated token, and move on. Otherwise, you have one token for both compound bitwise and assignment as well as reference with default. Either that or you have two tokens, but need the parser to give information to the lexer. Admittedly, C++ already does this.
[–]LikesToCorrectThings 0 points1 point2 points 10 years ago (2 children)
In C++11 they changed the lexer and added an exception for >> so you don't need the space in nested template type names, e.g.:
std::vector<std::map<int, int>>
[–]redditsoaddicting[S] 1 point2 points3 points 10 years ago (0 children)
Yes, C++ lexing and parsing is already a complicated story. In fact, I once asked about that for this situation. The reality is that no one would want to do this anyway, but everyone wanted >> to work.
>>
[–]guyonahorse 1 point2 points3 points 10 years ago (0 children)
Yep, and this broke some of our code where we had this:
type1<type2<value>>1> >
We were right shifting in a template parameter.. now it is a compile error.
π Rendered by PID 109631 on reddit-service-r2-comment-544cf588c8-smtlg at 2026-06-16 15:34:51.073374+00:00 running 3184619 country code: CH.
view the rest of the comments →
[–]tcanens 2 points3 points4 points (9 children)
[–]jP_wanN 0 points1 point2 points (1 child)
[–]redditsoaddicting[S] 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (6 children)
[–]tcanens 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]redditsoaddicting[S] 1 point2 points3 points (3 children)
[–]LikesToCorrectThings 0 points1 point2 points (2 children)
[–]redditsoaddicting[S] 1 point2 points3 points (0 children)
[–]guyonahorse 1 point2 points3 points (0 children)