How to make a multidimensional array of indefinite size a member of a class in C ++?

I look at a multidimensional library array from a raise, and I am having trouble figuring out a way to declare a multi_array element in a header file with an undefined form, like "A" in the example below:

Class.h

std::size_t nX;
std::size_t nY;
std::size_t nZ;

boost::multi_array<double, 3> A;

which is then created at a specific size in the source file:

Class.C ++

nX = 3
nY = 4
nZ = 2

A = boost::multi_array<double, 3>(boost::extents[nX][nY][nZ]);

but it gives me an error of unequal shape. Is there a way to do what I'm trying?

Ultimately, I need a member container to hold 3D data of a certain size. This worked with boost::numeric::ublas::matrixfor two dimensions without problems, but now I need something that will work for three dimensions.

- , / multi_array , ?

+2
1

A = boost::multi_array<double, 3>(boost::extents[nX][nY][nZ]);

resize()

A.resize(boost::extents[nX][nY][nZ]);
+1

All Articles