c++ - 为什么不能像这样传递参数?

标签 c++ pointers

我有一个函数:

int getCaseNum(float isovalue,float *F,int **point,int *dims,float *F_value)
 {

int digtial_point[8];
int case_num=0;
int i = 0;
for(i=0;i<8;i++)
{
    F_value[i] = F[GetPointIndex(point[i],dims)];
    if(F_value[i]>isovalue)
    {
        digtial_point[i] = 1;
        case_num = case_num + powf(2,i);
    }
    else
    {
        digtial_point[i] = 0;
    }


}

return case_num;

 }

然后我想像这样在另一个函数中调用这个函数:

int pointID[8][3];
int case_num = getCaseNum(isovalue,F,pointID,dims,F_value);

但是,当我编译我的代码时,它说:

/Users/liyuanliu/Documents/lecture/sicvis/final_6b/mc510/proj6B.cxx:862:24: error: 
  no matching function for call to 'getCaseNum'
    int case_num = getCaseNum(isovalue,F,pointID,dims,F_value);
                   ^~~~~~~~~~
/Users/liyuanliu/Documents/lecture/sicvis/final_6b/mc510/proj6B.cxx:816:5: note: 
  candidate function not viable: no known conversion from 'int [8][3]' to
  'int **' for 3rd argument
int getCaseNum(float isovalue,float *F,int **point,int *dims,float *F_value)
^

为什么会这样?我不能像这样传递参数吗?

最佳答案

// Create a dynamic 2D int array
int **pointID=new int*[8];
for(int i=0;i<8;i++) {
    pointID[i]=new int[3];
}
int case_num=getCaseNum(isovalue,F,pointID,dims,F_value);

关于c++ - 为什么不能像这样传递参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33704556/

相关文章:

c++ - 在模板的情况下包含头文件。

c++ - return 语句是否为按值返回的函数创建一个临时对象?

c++ - 使用 Vectors 的 Mergesort 排序不正确

c++ - 文件可以以 0x80 字符结尾吗?

c++ - 导致未定义行为的悬挂引用

c++ - 通过函数初始化指针

c - 链接列表打印问题?

C: malloc,结构错误

c - 如何调试链表程序?

c++ - 智能指针的使用