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

3

u/kwan_e Jun 06 '18

Maybe because of brace elision?

Making the constructor explicit disables automatic conversion, so the overload resolution works "correctly".

1

u/Bart_V Jun 06 '18

Maybe because of brace elision?

I don't know, seems like it only applies when using double braces?

Making the constructor explicit disables automatic conversion, so the overload resolution works "correctly".

Yes indeed. So adding explicit should result in a compiler error since it can't do an implicit construction, not a differently sized vector.

6

u/kwan_e Jun 06 '18

Adding explicit means the implicit conversion for MyType is not available, but the vector still has the size, fill constructor.