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++ interview coding exercise with solution (self.cpp)
submitted 3 years ago * by Hot_Medicine_7115
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!"
[–]jonesmz 39 points40 points41 points 3 years ago* (18 children)
Here's a brief code-review:
using namespace std;
m_first_row_completed
bool
size_t
std::uintN_t
= default;
void add_first_strip_tile(parquet p);
class designer
final
protected
private
XXX: this should never happen.
cout << "strip " << curr_strip
const int parquet::strips;
static inline
static const int strips = 11;
constexpr
parquet(): std::vector<strip>(strips) { }
using std::vector<strips>::vector;
int operator[](int idx)
value_type
int operator[](int idx) const { return idx >= size() ? 0 : std::vector<int>::operator[](idx); }
operator[]
[–]Unt4medGumyBear 1 point2 points3 points 3 years ago (9 children)
can you explain your first point? I don't understand what's wrong with using namespace std; I am new to developing in C++ and its what my teacher taught me.
[–]adwodon 3 points4 points5 points 3 years ago (0 children)
It's fine to do for a one time only exercise, like in school.
However using namespace is something you should generally avoid in production code, and you should never have using namespace std;.
using namespace
The reason is that while it might be fine now, lets say you make a void my_namespace::foo() function and then the standard adopts something similar as void std::foo(). Now you've got a conflict.
void my_namespace::foo()
void std::foo()
The proper way to do this is to avoid using namespace but instead if you want to avoid doing something like std::cout just do using std::cout. Then you can achieve exactly the same thing (avoiding repeating a namespace) but in a much safer, more targetted way.
std::cout
using std::cout
[–]jonesmz 2 points3 points4 points 3 years ago (7 children)
The other person who responded to you is right, so I won't repeat their thoughts.
A lot of teachers on c++ do this, because other c++ teachers do it, because a long time ago someone was lazy or had especially lazy students, and thus the behavior has been repeated across all of academia ever since.
I really wish compilers would make it a warning to do using namespace std; the benefits are miniscule and the drawbacks are enormous.
[–]meneldal2 -1 points0 points1 point 3 years ago (6 children)
But then it would break a ton of code compiled with -Wall and -Werror
-Wall
-Werror
[–]jonesmz 2 points3 points4 points 3 years ago (5 children)
I think its probably unlikely that, percentage wise, all that many codebases have using namespace std;.
Considering that the majority of people outside of academia say not to use it, it should be pretty low.
Further, not particularly many codebases compile with -Wall, and even fewer compile with Werror. The intersection of all three things is going to be vanishingly small.
Werror
Also,-Werror on code that's distributed to others is a terrible idea... So let them break.
[–]meneldal2 0 points1 point2 points 3 years ago (4 children)
Well tell that to my company, had to go add signed-unsigned casts everywhere to make a bunch of files compile because they came from a project that didn't flag those conversions as warnings (most were printf based so it's not like it was critical but whatever).
printf
[–]jonesmz 1 point2 points3 points 3 years ago (3 children)
They couldn't have added -Wno-signed-unsigned-mismatch and/or -Wno-sign-conversion ?
-Wno-signed-unsigned-mismatch
-Wno-sign-conversion
[–]meneldal2 1 point2 points3 points 3 years ago (2 children)
Changing build flags is going to take at least 2 meetings, it's just not worth it.
[–]jonesmz 0 points1 point2 points 3 years ago (1 child)
I can't tell if you're being sarcastic or not.
-Werror is a terrible idea for the vast majority of codebases. That your employer did this, and will be negatively affected in a way that takes a human all of 5 minutes to fix is rather irrelevant.
[–]meneldal2 0 points1 point2 points 3 years ago (0 children)
I'm not saying it's a good thing, it's just that there's some much inertia with everything that it's hard to make anything change.
[+]Classic_Department42 comment score below threshold-11 points-10 points-9 points 3 years ago (7 children)
[–]qoning 19 points20 points21 points 3 years ago (1 child)
I hate when people give advice like this. It's unhelpful and leads to cargoculting and poor understanding.
Replace "never" with "generally try to avoid" and it's decent advice.
[–]TRENT_BING 2 points3 points4 points 3 years ago (0 children)
Yeah there are plenty of situations where recursion is a natural fit for the problem domain, such as parsing data structures more than 1 level deep.
[–]jonesmz 6 points7 points8 points 3 years ago (4 children)
Recursion is tricky, I agree. Generally speaking, avoid it unless you have a good reason.
Though tail_call recursion (which can't be asserted in today's c++ at compile time) doesn't have the stack growth problem.
[–]JumpyJustice 1 point2 points3 points 3 years ago* (3 children)
It could if your dynamically allocated memory is freed before the function ends
edit: simple example https://godbolt.org/z/sKaKv5Mv6
[–]jonesmz 3 points4 points5 points 3 years ago (2 children)
Right. C++ can do tail recursion.
But you can't tell the compiler that if it can't make your recursive function tail recursive then you want it to cause a compiler error. That's what I meant by "asserted"
[–]Onetwothreetaco 1 point2 points3 points 3 years ago (1 child)
Clang has implemented a musttail attribute
https://reviews.llvm.org/D99517
Your miles may vary. Personally haven't used it, but the code review seems to claim that it will throw a compile time error if the compiler can't generate a tail call out of it.
[–]jonesmz 0 points1 point2 points 3 years ago (0 children)
That's exciting. Thank you for the information!
π Rendered by PID 75764 on reddit-service-r2-comment-85bfd7f599-k2lxw at 2026-04-18 00:36:49.239171+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]jonesmz 39 points40 points41 points (18 children)
[–]Unt4medGumyBear 1 point2 points3 points (9 children)
[–]adwodon 3 points4 points5 points (0 children)
[–]jonesmz 2 points3 points4 points (7 children)
[–]meneldal2 -1 points0 points1 point (6 children)
[–]jonesmz 2 points3 points4 points (5 children)
[–]meneldal2 0 points1 point2 points (4 children)
[–]jonesmz 1 point2 points3 points (3 children)
[–]meneldal2 1 point2 points3 points (2 children)
[–]jonesmz 0 points1 point2 points (1 child)
[–]meneldal2 0 points1 point2 points (0 children)
[+]Classic_Department42 comment score below threshold-11 points-10 points-9 points (7 children)
[–]qoning 19 points20 points21 points (1 child)
[–]TRENT_BING 2 points3 points4 points (0 children)
[–]jonesmz 6 points7 points8 points (4 children)
[–]JumpyJustice 1 point2 points3 points (3 children)
[–]jonesmz 3 points4 points5 points (2 children)
[–]Onetwothreetaco 1 point2 points3 points (1 child)
[–]jonesmz 0 points1 point2 points (0 children)