我有這樣的結構初始化用戶的矢量的矢量定義
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
使用初始化程序列表。 – Kunal