declare initialize vector inside struct/class
how declare initialize vector inside struct/class
1 2 3 4 5
|
struct Data {
int m=9;
vector<int> mydata(m);
}
|
gcc comes with
1 2
|
error: ‘m’ is not a type
| vector<int> mydata(m);
|
and
1 2 3
|
struct Data {
vector<int> mydata(m);
}
|
gcc comes with
1 2
|
error: expected identifier before numeric constant
25 | vector<int> mydata(9);
|
Last edited on
So what exactly is a mydata()?
Sounds like the mydata is a member variable and that you want it to have 9 elements.
1 2 3 4 5 6
|
struct Data {
vector<int> mydata;
Data() : mydata(9) {} // default constructor
Data(int m) : mydata(m) {} // custom constructor
};
|
Topic archived. No new replies allowed.