无法将double [] []转换为double ** [英] Cannot convert double [] [] to double **

查看:1201
本文介绍了无法将double [] []转换为double **的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数需要3个参数,第一个是** double。

I ve got a function that takes 3 parameteres, first one is **double.

 normalizeDataZeroMeanUnitSD(double ** trainingActions, int numberOfTrainingActions, int descriptorDimension)



当我从main调用它,我试图使用normalizeDataZeroMeanUnitSD数据,681,24);但是,我收到

When I call it from main, I am trying to use normalizeDataZeroMeanUnitSD(data, 681, 24); however, I am receiving

cannot convert parameter 1 from 'double [681][24]' to 'double **'

这是我如何构造数据数组:

This is how I construct the data array:

fstream infile;
infile.open("gabor\\Data.txt");

double data[681][24];

while (!infile.eof()) 
     {
        for(int j=0;j<681;j++) 
        {
            for(int k=0; k<24;k++) 
            {

                infile >> data[j][k];

           }

        }

 } 
 infile.close();

有办法使用**数据做同样的事吗?

Is there a way to do the same using **data?

推荐答案

使用以下任何声明。两者都是等效的。

Use any of the following declarations. Both are equivalent.

NormalizeDataZeroMeanUnitSD(double trainingActions[][24], int numberOfTrainingActions, int descriptorDimension)

NormalizeDataZeroMeanUnitSD(double trainingActions[681][24], int numberOfTrainingActions, int descriptorDimension)

声明一个2D数组,它占用连续的内存位置。因此,您至少需要指定列数(在行主体架构的情况下)。

When you declare a 2D array it takes up contiguous memory locations. So you need to specify at least the number of columns (in case of row major architecture).

对于行主要和列主要定义,请查看

For row major and column major definitions, have a look at this.

对于您编辑的问题,是的,您可以使用 ** data 声明。动态分配数据数组。但请记得在完成后释放它。

For your edited question, yes you can declare using **data. Dynamically allocate the data array. But remember to free it when you're done with it.

double **data=new double*[681];
for (int i=0;i<681;i++)
{
  data[i]=new double[24];
}

//do what you want to do


for (int i=0;i<681;i++)
{
  delete [] data[i];
}

delete [] data;

现在你的函数原型可以像 void func ,因为 data 是不是2D数组的指针。

Now your function prototype can be like void func(double **pp) because data is a pointer not a 2D array.

这篇关于无法将double [] []转换为double **的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆