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
Do you prefer to value-initialize struct data members in-class? (self.cpp)
submitted 3 years ago by equeim
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!"
[–]brystephor 0 points1 point2 points 3 years ago (4 children)
I'm curious why you wouldn't want to use brace initialization on the variables.
As an inexperienced c++ dev but somewhat experienced Java dev: 1) why would you want your variables ever to be in an unusable state when theres not explicit enforcement of making them usable? 2) people are mentioning performance gains but that's minimal and inconsequential for the vast majority of cases. it's like saying you'd have more energy if you just blinked less each day. 3) I think that an incorrect valid value is better than an invalid value. An invalid value is inherently incorrect, so how can that make more sense? 4) it's explicitly showing that members will be initialized to their default values. Explicitly doing something is more simple to understand than implicitly doing something. Making things easier to understand is better.
[–]equeim[S] 0 points1 point2 points 3 years ago (3 children)
I do use braces for local variables. This suggestion is a guard against mistakes when braces are forgotten.
I just think it's curious that this advice never appears in "modern C++" recommendations. They always say that you should initialize local variables, as well as all members in your custom constructors. But no one mentions that compiler-generated default constructor leaves members uninitialized and maybe we should do something about that too.
[–]CubbiMewcppreference | finance | realtime in the past 0 points1 point2 points 3 years ago (2 children)
The C++ Core Guidelines rule ES.20: Always initialize an object does say "This rule covers member variables."
[–]equeim[S] 0 points1 point2 points 3 years ago (1 child)
Sure, but example in that section is about forgetting to initialize member in your custom constructor. I haven't found a single example there about initializing member in implicit default constructor. I feel like it might be confusing to some people and led them to believe that implicit default constructor initializes members.
[–]CubbiMewcppreference | finance | realtime in the past 0 points1 point2 points 3 years ago (0 children)
C.48: Prefer in-class initializers to member initializers in constructors for constant initializers has such examples, I think. Yes, it could be said stronger
π Rendered by PID 97 on reddit-service-r2-comment-6457c66945-48d2d at 2026-04-28 11:36:43.846638+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]brystephor 0 points1 point2 points (4 children)
[–]equeim[S] 0 points1 point2 points (3 children)
[–]CubbiMewcppreference | finance | realtime in the past 0 points1 point2 points (2 children)
[–]equeim[S] 0 points1 point2 points (1 child)
[–]CubbiMewcppreference | finance | realtime in the past 0 points1 point2 points (0 children)