初始化矢量的矢量大小

Initialize size of vector of vectors

本文关键字:初始化      更新时间:2023-10-16

如何用30个空向量声明大小为30的向量。我试过

vector< vector<T> > vec(30);

但返回时出现错误:

./HashSet.h:62:28: error: expected parameter declarator
         vector< vector<T> > table(30);
                              ^
./HashSet.h:62:28: error: expected ')'
./HashSet.h:62:27: note: to match this '('
    vector< vector<T> > table(30);

这将创建一个由30个矢量组成的矢量,每个矢量包含30个元素:

vector< vector<T> > vec(30, vector<T>(30));

但它要求T是默认可构造的。