3 ms·
Around the 30 minute-mark, I noticed some weird syntax that I've never seen before. I dabble in C++ at my job, so I'm not a total newbie. But what do those brac
by nrclark 8y ago
Around the 30 minute-mark, I noticed some weird syntax that I've never seen before. I dabble in C++ at my job, so I'm not a total newbie. But what do those braces mean on 'weekday'? Is that some kind of class constructor or something?
Code in question was:
cout << weekday{October/19/2017} << '\n';
- bstamour 8y agoIt's an example of uniform initialization syntax that was brought into the language in C++11. It simplifies some things (no narrowing conversions allowed) but also complicates things (if any constructor takes in an initialize-list, it gets priority). In this case, the code is constructing an object of type weekday from an expression that represents that particular date.
- Game_Ender 8y agoIt's "aggregate initialization" [0] struct S { int x; struct Foo { int i; int j; int a[3]; } b; }; S s1 = { 1, { 2, 3, {4, 5, 6} } }; 0 - https://en.cppreference.com/w/cpp/language/aggregate_initialization https://en.cppreference.com/w/cpp/language/aggregate_initial...
- planteen 8y agoI don't think that is what is going on, this is invoking the constructor for the weekday class with the "modern" uniform initilization syntax. This solves the old C++ most vexing parse problem. https://en.wikipedia.org/wiki/Most_vexing_parse https://en.wikipedia.org/wiki/Most_vexing_parse It seems like this is the C++ class in question: https://howardhinnant.github.io/date/iso_week.html https://howardhinnant.github.io/date/iso_week.html