1

I have a function:

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;

 }

Then I want to call this function in another function like this:

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

However, when I compile my code, it says:

/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)
^

Why this happens ? Cannot I pass parameter like this?

beasone
  • 1,073
  • 1
  • 14
  • 32

2 Answers2

0
// 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);
William Chan
  • 277
  • 2
  • 12
0

you need to get a pointer to first entry in 2D array. Since array is contiguous, you can use below logic to iterate

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

    for (i = 0; i < 24; i++)
    {
        cout << *(point+i*sizeof(int));
    }
}

caller:

int case_num = getCaseNum(isovalue,F,&pointID[0][0],&dims,F);
Nandu
  • 808
  • 7
  • 10