titanandrews
Programmer
Hi,
I am using the sort() function from <algorithm> and trying to use a member function for the sort implementation.
Like this:
If I remove the SortAsc() function from the class, then it works fine i.e. (bool SortAsc(const string& x, const string& y), but this function must be a member function because I HAVE to access member variables. How can I make this function a member and reference it from the sort() function. I have tried
Nothing works. I get compiler errors.
many thanks to you,
Barry
I am using the sort() function from <algorithm> and trying to use a member function for the sort implementation.
Like this:
Code:
bool MyView::SortAsc(const string& x, const string& y)
{
//do some sorting
return true;
}
void MyView::MySortCaller()
{
vector<string> myVect;
//Put some stuff in them
sort(myVect.begin(),myVect.end(),SortAsc);
}
If I remove the SortAsc() function from the class, then it works fine i.e. (bool SortAsc(const string& x, const string& y), but this function must be a member function because I HAVE to access member variables. How can I make this function a member and reference it from the sort() function. I have tried
Code:
sort(myVect.begin(),myVect.end(),this->SortAsc);
sort(myVect.begin(),myVect.end(),SortAsc);
sort(myVect.begin(),myVect.end(),MyView::SortAsc);
Nothing works. I get compiler errors.
many thanks to you,
Barry