I am trying to utilize the selection sort algorithm to sort an array of object pointers on an int that is a member variable of each object. The getter function is getVar() and works properly. Obviously, what I have here won't work, as I end up trying to swap an int with an object pointer. I sure I'm missing something along the lines of declaring and using anObject* = temp, but I'm just not grasping it. (I see several somewhat similar questions on this topic, but none are quite like this.) Thank you.
void selectSort(anObject* array[], int size) {
int i;
int minIdx;
int minVal;
for (i = 0; i < (size - 1); i++) {
minIdx = i;
minVal = array[i]->getVar();
for (int index = i + 1; index < size; index++) {
if (array[index]->getVar() < minVal) {
minVal = array[index]->getVar();
minIdx = index;
}
}
array[minIdx] = array[i];
array[i] = minVal; // invalid conversion from int to *anObject
}
}