The size of the vector became 2. It casts the integer (6) to double, then constructs a MyType, then used vector( std::initializer_list<T> init). I don't understand why, and gave up trying to. Also, since it's in-class initialization, for whatever reason I can't use parentheses there, which would have given the correct result.
What's even more worrying is that making MyType's ctor explicit, does result in a vector with the expected size of 6. Which means a making small change like that could silently break other pieces of code. So IMHO, braced initialization is completely messed up.
5
u/Bart_V Jun 06 '18
That's especially a situation where I avoid them. I've shoot myself in the foot too many times. Just recently, I did this:
And then somewhere else I was trying to do in-class initialization of a vector using the
vector( size_type count, const T& value)ctor like this:The size of the vector became 2. It casts the integer (6) to double, then constructs a
MyType, then usedvector( std::initializer_list<T> init). I don't understand why, and gave up trying to. Also, since it's in-class initialization, for whatever reason I can't use parentheses there, which would have given the correct result.What's even more worrying is that making
MyType's ctorexplicit, does result in a vector with the expected size of 6. Which means a making small change like that could silently break other pieces of code. So IMHO, braced initialization is completely messed up.