【发布时间】:2013-11-01 13:16:14
【问题描述】:
我有这个结构
struct myStruct {
int a;
int b;
}
我想创建一个vector <vector<myStruct> > V 并将其初始化为n 类型为vector<myStruct> 的空向量
我正在尝试使用fill constructor 像这样:
vector<edge> temp;
vector<vector<edge> > V(n, temp);
这段代码在main 中运行良好,但是当我在一个类中有V 时,我如何在类构造函数中做到这一点。
编辑:
当我在类构造函数中执行此操作时,出现以下错误:no match for call to '(std::vector<std::vector<edge> >) (int&, std::vector<edge>&)'
产生错误的代码是:
vector<myStruct> temp;
V(n, temp); // n is a parameter for the constructor
【问题讨论】:
-
使用初始化列表。
标签: c++ vector initialization