I've been having problems trying to pass a struct pointer array in dynamic memory to a function. Could anyone please help me with where i've gone wrong?
I've cut out chunks of code that (hopefully) don't relate to the function.
I keep getting this error message:
error C2664: 'QuickSort' : cannot convert parameter 1 from 'person **' to 'person **[]'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
I've tried different combinations of []'s but no luck. Can anyone help with what i'm doing wrong? Would be much appreciated.
//Before main
void QuickSort(person** arr[], int left, int right);
//In main
person** pointerset = new person*[FL];
//(more code)...
QuickSort(pointerset, 0, FL - 1);
//After main
void QuickSort(person** arr[], int left, int right) {
int i = left, j = right;
person** tmp;
//pivot is abritrary middle value
int pivot = (**(arr[(left + right) / 2])).mobile;
//
/* partition */
while (i <= j) {
while ((**(arr[i])).mobile < pivot)
i++;
while ((**(arr[j])).mobile > pivot)
j--;
if (i <= j) {
tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
i++;
j--;
}
};
/* recursion */
if (left < j)
QuickSort(arr, left, j);
if (i < right)
QuickSort(arr, i, right);
}
//Quicksort taken and adapted from http://www.algolist.net/Algorithms/Sorting/Quicksort
I assume you are passing pointerset, which would explain your error. In an argument list, [] and * are used interchangeably. Therefore, in your arg list you want *** (which you represent as **[]) and you are passing a **. These are two different levels of pointerness (or dereferenceability, whatever you want to call it) so the call is in error.
EDIT: You may want to check the tutorial for arrays and passing them to functions, on this website. Passing a * is the same as passing a [].
ah yeh... i kept presuming it was wrong because i got even more errors relating to the pointers inside the function, but it was those that needed editing after getting rid of the [].