I'm trying to define a bunch of structs in a header file. For example:
struct Firststruct{
int useless;
};
struct Secondstruct{
Firststruct* struct1; // we want to have a dynamic array here.
};
struct Thirdstruct{
Secondstruct* struct2; // we want to have a dynamic array here.
};
And for simple usage in main or source file. We want to define the struct constructor. For example:
struct Secondstruct{
Firststruct* struct1; // we want to have a dynamic array here.
// constructor
Secondstruct(int num_struct1){
struct1 = new Firststruct[num_struct1];
};
// deconstructor
blablabla
};
So here is the question, how could we define the constructor in Thridstruct?
struct Thirdstruct{
Secondstruct* struct2; // we want to have a dynamic array here.
// constructor
Thirdstruct(int num_struct2){
struct2 = new Secondstruct[num_struct2]; // this of couse does not work.
};
// deconstructor
blablabla
};
I am new in C++, so I do not know how to write it. Could someone provide some ideas?
Thanks. :)