Why does the number of elements in a initializer list cause an ambiguous call error?

前端 未结 3 1838
野性不改
野性不改 2020-12-29 18:02

Why are the first two calls to doSomething OK by the compiler, but using two elements in the list causes an ambiguous call?

#include 

        
3条回答
  •  青春惊慌失措
    2020-12-29 18:09

    Both the one-argument and three-argument lists can only match std::vector's std::initializer_list constructor. However, the two-argument list matches one of the constructors from std::vector:

    template 
    vector(InputIt first, InputIt last, Allocator const &alloc = Allocator());
    

    Indeed, a char const * can be incremented, and dereferenced to get a char that is implicitly convertible to an int.

提交回复
热议问题