如何使不定尺寸的多维数组成为c ++中的类的成员? [英] How do I make a multidimensional array of undetermined size a member of a class in c++?
问题描述
Class.h
std :: size_t nX;
std :: size_t nY;
std :: size_t nZ;
boost :: multi_array< double,3>一个;
这些文件在源文件中被实例化为一定大小:
Class.c ++
nX = 3
nY = 4
nZ = 2
A = boost :: multi_array< double,3>(boost :: extent [nX] [nY] [nZ]);
但这给我一个不平等的形状错误。有没有办法做我正在尝试的事情?
最终,我需要一个成员容器来存储一个要确定的后期大小的三维数据。这个工作与 boost :: numeric :: ublas :: matrix
有两个维度没有问题,但现在我需要一些可用于三维的东西。
任何人都可以告诉我如何使用multi_array类可以实现,或者通知我另一个可能会工作的库?
而不是
A = boost :: multi_array< double,3& ::区段[NX] [NY] [nZ上]);
您需要调用 resize()
函数作为
A.resize(boost :: extents [nX] [nY] [nZ]);
I am looking at the multidimensional array library from boost, and I'm having trouble figuring out a way to declare a multi_array member in the header file with an undefined shape, 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 later instantiated to a certain 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 this gives me an unequal shape error. Is there any way to do what I am attempting?
Ultimately, I need a member container to store three-dimensional data of a to-be-determined-later size. This worked with boost::numeric::ublas::matrix
for two dimensions without a problem, but now I need something that will work for three dimensions.
Can anyone tell me how/if this is possible with the multi_array class, or inform me of another library that might work instead?
instead of
A = boost::multi_array<double, 3>(boost::extents[nX][nY][nZ]);
you need to call resize()
function as
A.resize(boost::extents[nX][nY][nZ]);
这篇关于如何使不定尺寸的多维数组成为c ++中的类的成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!