是.使用std :: initializer_list.
在类中定义一个构造函数,它接受std::initializer_list:
std::initializer_list
MyVectorClass(std::initializer_list initializer) { for(T& i : initializer) { // Do whatever you want with items } }