Congratulations, you just came across a canonical example of why you should prefer force initialization if your compiler supports it.
If you want std::vector two elements, you use:
vector<int> v = { 10, 20 };
If you use vector<int> v(10,20); , you are actually a constructor that accepts two integer convertible elements that are explicit vector (size_type n, const value_type& val = value_type(), const allocator_type& alloc = allocator_type()); . Remember that std::vector was added to the language in C ++ 98, while in braced-initialization mode it is added before C ++ 11.
See Basic C ++ recommendations , in particular ES.23: Prefer {} initiator syntax
source share