如何使用显式元素初始化器初始化向量?

q09*_*987 3 c++

我们可以使用以下语法来初始化向量.

// assume that UserType has a default constructor
vector<UserType> vecCollections; 
Run Code Online (Sandbox Code Playgroud)

现在,如果UserType没有为UserType提供默认构造函数,而只提供构造函数,如下所示:

explicit UserType::UserType(int i) { ... }.
Run Code Online (Sandbox Code Playgroud)

我应该如何使用向量构造函数调用此显式元素初始值设定项?

Eri*_*rik 11

vector<UserType> vecCollections(10, UserType(2));
Run Code Online (Sandbox Code Playgroud)