someone said try a vector, so I tried:... but failed
You can use vector as shown below. In the shown program, we have a data member called nds
of type vector<t_nd>
. Also, we have a constructor that has a parameter of type std::size_t
.
struct t_nd {
double stuff;
};
struct t_nwork {
//data member of type std::vector<t_nd>
std::vector<t_nd> nds;
//constructor to set size of vector
t_nwork(std::size_t psize): nds(psize)
{
}
};
int main()
{
//create object of type t_nwork whose nds have size 10
t_nwork net(10);
}
Working demo
Method 2
Here we don't have any constructor to set the size of the vector.
struct t_nd {
double stuff;
};
struct t_nwork {
//data member of type std::vector<t_nd>
std::vector<t_nd> nds;
};
//create object of type t_nwork whose nds have size 10
t_nwork net{std::vector<t_nd>(10)};
Demo