Reputation: 252
I've got a class that gets a 3-dimensional struct array in the constructor. For further calculations it also needs the length of each dimension.
a short example:
MyStruct*** mySt;
mySt = new MyStruct**[5]
mySt[0] = new MyStruct*[4]
mySt[0][0] = new MyStruct[3]
How can I get those values (5, 4, 3) back to save them in the new class without explicitely sending them to the constructor?
Upvotes: 3
Views: 84
Reputation: 726489
You cannot get sizes from plain C++ arrays allocated with new
and stored as pointers: there is no language construct that would let you retrieve an array size.
There are two options for how to deal with this situation:
std::vector
of vectors of vectors, ormySt
array.Upvotes: 3