错误 "subscript of pointer to function type 'int *(int)'"

Error "subscript of pointer to function type 'int *(int)'"

我正在编写代码来查找集群,我正在使用 "cern root" 绘制图表, 数据保存在“.root”文件中,但代码是用 C++ 编写的。数据保存为二维直方图。代码的逻辑是,一旦我找到一个带有一些信号的箱子,我就会找到它周围的邻居(8 个箱子),然后我标记箱子并增加集群大小,然后对邻居做同样的事情。我首先编造了一个寻找邻居的小说(函数returns 一个带有x坐标的数组,另一个找到y坐标)

int* neighbour_function_i(int i){   
int* neighbour_i = new int[8];   // Pointer to int, initialize to nothing.
neighbour_i[0] = {i-1}, neighbour_i[1] = {i}, neighbour_i[2] = {i+1}, neighbour_i[3] = {i-1}, neighbour_i[4] = {i+1}, neighbour_i[5] = {i-1}, neighbour_i[6] = {i}, neighbour_i[7] = {i+1};
return neighbour_i; //check if this works
}

找到集群的代码如下

    int* temp_neighbour_i = NULL;
    int* temp_neightbour_j = NULL;
    int uncheckedneighbours, total_neighbours;
    int clsize = 0;
    int temp_i,temp_j;

  for(int i = 0; i < NPIXAX; i++){
    for(int j = 0; j < NPIXAY; j++){
        clsize = 0;
        if(h->GetBinContent(i + 1, j + 1) - ped[i][j] > 0 && pedbf[i][j] == 0){//condition to find a cluster
           pedbf[i][j] = 1; //Tag arry
           clsize = 1;
           uncheckedneighbours = 8;
           total_neighbours = uncheckedneighbours;
           int* neighbour_i = neighbour_function_i[i];//the error is here
           int* neighbour_j = neighbour_function_j[j];//the error is here
           while(uncheckedneighbours != 0){
              for(int n = 0; n < total_neighbours; n++){
                temp_i = neighbour_i[n];//Temp int for coordienate 
                temp_j = neighbour_j[n];//Temp int for coordinate
                if(h->GetBinContent(temp_i, temp_j) - ped[temp_i][temp_j] > 0 && pedbf[temp_i][temp_j] == 0){//condition to find a cluster
                    pedbf[temp_i][temp_j] = 1;
                    int* new_neighbour_i = neighbour_function_i[temp_i];//the error is here
                    int* new_neighbour_j = neighbour_function_j[temp_j];//the error is here
                    uncheckedneighbours += 8;
                    total_neighbours += 8; 
                    int* temp_neighbour_i = new int[clsize * 8];
                    int* temp_neighbour_j = new int[clsize * 8];
                    clsize++;
                    temp_neighbour_i[n] = neighbour_i[n];//moving data to chnage the size of neighbour/i array
                    temp_neighbour_j[n] = neighbour_j[n];//moving data to change the size of neighbour_j array
                    delete[] neighbour_i;//deallocate neighbour
                    delete[] neighbour_j;//deallocate neighbour
                    int *neighbour_i = new int[clsize * 8]; //re-allocate the size of neighbour with size = size(clsize *8)
                    int *neighbour_j = new int[clsize * 8]; //re-allocate the size of neighbour with size = size(clsize *8)
                    for(int x = 0; x < (clsize - 1) * 8; x++){ //neighbour = temp_neighbour + new_neighbour
                        neighbour_i[x] = temp_neighbour_i[x]; 
                        neighbour_j[x] = temp_neighbour_j[x]; 
                    }
                    for(int x = (clsize - 1)*8; x < clsize * 8; x++){
                        neighbour_i[x] = new_neighbour_i[x];
                        neighbour_j[x] = new_neighbour_j[x];
                    }
                    delete[]temp_neighbour_i; //dealocate temp and new
                    delete[]temp_neighbour_j; //dealocate temp and new
                    delete[]new_neighbour_i; //dealocate temp and new
                    delete[]new_neighbour_j; //dealocate temp and new
                }
                uncheckedneighbours--;
              }
           }
        //if(clsize != 0){;//output to file cluseter size, i, j
        //}
        }
    }
 }

我不确定为什么会收到此错误 "subscript of pointer to function type 'int *(int)'"?

也许问题应该因为打字错误而被关闭,但是一个函数是这样调用的:

int* neighbour_i = neighbour_function_i(i);

不是这样的:

int* neighbour_i = neighbour_function_i[i];