我们可以使用以下语法来初始化向量.
// 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)
| 归档时间: |
|
| 查看次数: |
3364 次 |
| 最近记录: |