[英]c++ how to initialize vector of 4 empty sets
For a vector of vectors, I would do this: 对于向量的向量,我会这样做:
vector<vector<int> > A(10, vector<int>(10));
So I tried this for a vector of sets: 所以我尝试了一个向量集:
vector < set <object*> > mySet(4, set<object*>);
..but it won't compile. ..但不会编译。 Any advice?
有什么建议吗?
You are almost right: even though you do not need to specify the size, you still need an empty pair of parentheses: 您几乎是对的:即使您不需要指定大小,您仍然需要一对空括号:
vector<set<object*>> vsi(4, set<object*>());
// ^^
Moreover, since you are using the default constructor, you could simply omit the second argument, like this: 而且,由于您使用的是默认构造函数,因此可以简单地省略第二个参数,如下所示:
vector<set<object*>> vsi(4);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.