About the constructor function.

Just take std::vector as an example.
I wonder which constructor function is called when executing std::vector<int> a{1,2,3}.
Thanks for your help.
That particular form of vector initialization is using list initialization, introduced in C++11.

https://en.cppreference.com/w/cpp/language/list_initialization
Last edited on
The std::vector had/has quite many constructors, as shown in https://en.cppreference.com/w/cpp/container/vector/vector

The {1,2,3} initializer syntax was introduced in C++11 and along with that:
1
2
vector( std::initializer_list<T> init,
        const Allocator& alloc = Allocator() );

The constructor which initialises the container with the contents of the initializer list
The one marked (10) in this list of overloads: https://en.cppreference.com/w/cpp/container/vector/vector

Note that the presence of list-initializing constructor (10) means list initialization and direct initialization do different things:
https://en.cppreference.com/w/cpp/container/vector/vector#Notes
Thanks for all answers. I have got it.
Topic archived. No new replies allowed.