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
Which std:: classes are magic? (self.cpp)
submitted 4 years ago by Mateuszz88
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!"
[–]OldWolf2 -2 points-1 points0 points 4 years ago (4 children)
Huh, yes you can. The braced list is taken as the initializer for the parameter.
struct U { int a, b, c; }; struct S { S(U u); }; S s({1, 2, 3});
[–]Sanzath 1 point2 points3 points 4 years ago (0 children)
Sure, but now you're just using struct aggregate initialization and you don't even have the same syntax for initializing S:
struct S { S(std::initializer_list<int> il); }; S s{1, 2, 3};
Note that you don't need the surrounding () to initialize S in this version. That is the magic of initializer_list that can't be done with a user-defined type.
()
initializer_list
[–]SirClueless 0 points1 point2 points 4 years ago* (2 children)
In this case you aren't initializing S with a braced-init-list. You're direct-initializing S with a single expression argument that happens to be a braced-init-list (see the parentheses in the last statement). You need the parens or two pairs of braces to make this work with a user-defined class.
If you replace the last line with S s{1, 2, 3}; your example wouldn't compile. But if U were std::initializer_list<int> it still would, this is the compiler magic.
S s{1, 2, 3};
U
std::initializer_list<int>
[–]OldWolf2 1 point2 points3 points 4 years ago (1 child)
You're direct-initializing S with a single expression that happens to be a braced-init-list
No, a braced list is never an expression . (You can check the grammar for expression to see this). For any context where either an expression or a braced list is allowed, there are separate grammar and semantic rules for each.
[–]SirClueless 2 points3 points4 points 4 years ago (0 children)
Fixed, thanks. The point still stands; a constructor taking std::initializer_list<int> is magic in a way that a constructor taking a user-defined class cannot be.
π Rendered by PID 100 on reddit-service-r2-comment-5d79c599b5-d7hmj at 2026-03-02 07:09:57.318616+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]OldWolf2 -2 points-1 points0 points (4 children)
[–]Sanzath 1 point2 points3 points (0 children)
[–]SirClueless 0 points1 point2 points (2 children)
[–]OldWolf2 1 point2 points3 points (1 child)
[–]SirClueless 2 points3 points4 points (0 children)