使用带有一个元素的初始化列表构造std :: vector [英] Construct std::vector using initializer list with one element
本文介绍了使用带有一个元素的初始化列表构造std :: vector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下程序,定义一个包含值13的std :: vector:
Consider the following program, defining a std::vector containing the value 13:
std::vector<int> vec{13};
这也可能被解释为对构造函数的调用,该构造函数将向量初始化为13个零.我的问题是:编译器如何在使用initializer_list构造std :: vector或通过用13个零初始化矢量之间进行选择?
This could also have been interpreted as a call to the constructor that initializes the vector with 13 zeros. My question is: how does the compiler choose between constructing a std::vector with an initializer_list or by initializing the vector with 13 zeros?
推荐答案
查看全文