Hi. I have a problem using STL's built in sort that seems impossible
to get around.
if i have:
--------------------------------
struct object
{
int val;
}
void main()
{
vector<object> objects;
vector<int> indices;
sort(indices.be gin(),indices.e nd(),compare)
}
--------------------------------
indices contains ints that refer to an index into the objects array
now, I want to sort the array "indices" based on the values in the
objects array that the integers in indices refer to. but i cannot
think of a legitimate compare funciton that could do this.
ideally i would have
bool compare(const int a, const int b, vector<object>& objects)
{
return(objects[a].val<objects[b].val)
}
but i cannot add that last parameter or i get compile problems.
"error C2064: term does not evaluate to a function taking 2 arguments"
does anyone know how to do this? thanks!
Oliver
to get around.
if i have:
--------------------------------
struct object
{
int val;
}
void main()
{
vector<object> objects;
vector<int> indices;
sort(indices.be gin(),indices.e nd(),compare)
}
--------------------------------
indices contains ints that refer to an index into the objects array
now, I want to sort the array "indices" based on the values in the
objects array that the integers in indices refer to. but i cannot
think of a legitimate compare funciton that could do this.
ideally i would have
bool compare(const int a, const int b, vector<object>& objects)
{
return(objects[a].val<objects[b].val)
}
but i cannot add that last parameter or i get compile problems.
"error C2064: term does not evaluate to a function taking 2 arguments"
does anyone know how to do this? thanks!
Oliver
Comment