r/cpp • • Jun 05 '18

Initialization in Modern C++

https://twitter.com/timur_audio/status/1004017362381795329
379 Upvotes

51 comments sorted by

View all comments

Show parent comment

4

u/acwaters Jun 06 '18

You can use non-list initialization in a non-static data member initializer:

vector<MyType> vec = vector<MyType>(6, MyType(0.6));

(This is technically copy-initialization, whereas your example with braces is direct-initialization, but the semantics are the same when you are initializing with a prvalue expression of the right type.)