简体   繁体   English

初始化向量的向量大小

[英]Initialize size of vector of vectors

How do I declare a vector of size 30 with 30 empty vectors.如何使用 30 个空向量声明大小为 30 的向量。 I've tried我试过了

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

But it returns with errors:但它返回错误:

./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);

This creates a vector of 30 vectors of 30 elements each:这将创建一个包含 30 个向量的向量,每个向量包含 30 个元素:

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

But it requires that T is default-constructible.但它要求 T 是可默认构造的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM