I need to pass different array of structures to function, but I don't know how to do it. Each time, I'm getting an error. I go through the Internet but all examples I found are about passing specific or only one array of structure to function (Passing array of structures to function c++) but what if I have different structures each time and I want to pass it to the same function.
So I'm not sure if what I want to do is applicable or not.
To clarify more if I have the following structures:
struct EVRL_Mapping2 {
double avgMap2;
int permutationMap2[2];
};
struct EVRL_Mapping3 {
double avgMap3;
int permutationMap3[3];
};
struct EVRL_Mapping4 {
double avgMap4;
int permutationMap4[4];
};
EVRL_Mapping2 EVRL_Map2[2]; //Mapping2: AC3,AC2 (2 mapping)
EVRL_Mapping3 EVRL_Map3[2]; //Mapping3: AC3,AC2,AC1 (2 mapping)
EVRL_Mapping4 EVRL_Map4[1]; //Mapping4: AC3,AC2,AC1,AC0 (1 mapping)
Now in the .CC code, if I have an array of two elements of EVRL_Mapping2 (EVRL_Map2[2]) and I want to find the maximum of avgMap2 between the two elements of structure and return the index/location of that element. Is it going to be like this: if yes, does it mean for each structure I need to define a separate function!?
int findMax(struct EVRL_Mapping2 myarray[], int size){
for(int i=0;i<size;i++){
// printf("myarray[%d]=%d\n",i,myarray[i]);
}
double max = myarray[0].avgMap2;
int index = 0;
for(int i = 1; i<size; i++)
{
if(myarray[i] > max){
max = myarray[i].avgMap2;
index = i;
printf("Inside if(): index=%d\n",index);
}
}
return index;
printf("Inside findMax(): index=%d\n",index);
}
Now calling and passing to this function:
findMax(EVRL_Map2,2);
However, I have an error with the above function definition and the code doesn't compile.So can you advise?
Thanks for your help in advance.