Ошибка "индекс указателя на функцию типа int * (int) '" - PullRequest
0 голосов
/ 05 мая 2020

Я пишу код для поиска кластера, я использую cern root для построения графиков, данные сохраняются в файле «. root», но код написан на c ++. Данные сохраняются в виде двухмерной гистограммы. Лог c кода: как только я нахожу контейнер с некоторым сигналом в нем, я нахожу соседей вокруг него (8 ячеек), затем я помечаю контейнер и увеличиваю размер кластера, а затем делаю то же самое для соседа . Я начал с выдумки, чтобы найти соседа (функция возвращает массив с координатой 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
        //}
        }
    }
 }

Я не уверен, почему я получаю эту ошибку «индекс указателя на функцию типа int * (int) '»?

1 Ответ

2 голосов
/ 05 мая 2020

Возможно, вопрос стоит закрыть как опечатку, но функция вызывается так:

int* neighbour_i = neighbour_function_i(i);

Не так:

int* neighbour_i = neighbour_function_i[i];
...