简体   繁体   中英

Initialize size of vector of vectors

How do I declare a vector of size 30 with 30 empty vectors. 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:

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

But it requires that T is default-constructible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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