I have a pointer to a vector of object pointers
vector<object*>* vec;
Which happens to hold information for objects that can currently be colliding with another object. This is great- but I need to sort this vector by distance from the root object, and I don’t know of the best way to do that.
As it stands the object sorts another temporary vector of another struct
struct tempsort{
int distanceFromObject;
object* obj;
}
With a function like this:
bool sorter(tempsort* first, tempsort* second){
return first->distanceFromObject < second->distanceFromObject;
}
Implementation:
vector<tempsort*> tosort;
for (int a = 0; a < vec->size(); a++){
tosort.push_back(new tempsort);
tempsort.distanceFromObject = distanceBetweenObjects(host,(*vec)[a]);
tempsort.obj=(*vec)[a];
}
sort(tempsort.begin(),tempsort.end(),sorter);
The object now resolves collisions.
Tempsort’s objects are now erased.
However I’d really like to sort the original vector instead of creating this temporary vector. Is that possible? If so, how?
Try functor with parameters: