我有一个函数,其中包含一个void * buffer参数。这个函数(由HDF here提供,根据我的理解,它从一个数据集中读取信息到缓冲区中,我有这个工作,但是只有当我使用常量值创建一个3d int数组时,我需要能够做到这一点使用由用户传递价值 这里是函数的开始:。使用传入参数在C++中创建一个3D数组
void* getDataTest(int countX, int countY)
{
int NX = countX;
int NY = countY;
int NZ = 1;
int data_out[NX][NY][NZ]; //I know this doesn't work, just posting it for reference
//.
//. more code here...
//.
// Read function is eventually called...
h5Dataset.read(data_out, H5::PredType::NATIVE_INT, memspace, h5Dataspace);
}
这不断失败,对我然而,我在创建时使用const int的值previoud实施DATA_OUT阵列工作得很好:
void* getDataTest(int countX, int countY)
{
const int NX = 5;
const int NY = 5;
const int NZ = 1;
int data_out[NX][NY][NZ];
//.
//. more code here...
//.
// Read function is eventually called...
h5Dataset.read(data_out, H5::PredType::NATIVE_INT, memspace, h5Dataspace);
}
这工作正常。从我的理解,这个功能(我没有连续rol over)需要具有相同维度的数据空间(例如,一个3D阵列只能用于3D阵列,而2D阵列只能在将数据复制到缓冲区时与2D阵列一起工作)。
所以,我的关键问题是,我似乎无法弄清楚如何创建一个读取函数满意的3D int数组(函数参数是一个void *,但我似乎无法得到除了3d int数组以外的其他任何东西)。我已经尝试了一个3D int数组,用阵列阵列表示:
int*** data_out = new int**[NX];
但是这也失败了。关于如何创建一个形式为int arrayName [非常量值] [非常量值] [非常量值]的3D int数组的任何想法?我知道你不能使用非常量值创建一个数组,但为了澄清我的目标,我添加了它们。在C++中是否应该使用函数参数作为实例化数组的值?
我觉得这是你想链接到的方法:https://support.hdfgroup.org/HDF5/doc/cpplus_RM/class_h5_1_1_data_set.html#a2f0278a519122419ae9981666277c9bb – Creak
谢谢,我更新了这篇文章。 – Roka545