Virtual methods as Comp function to sort
- by wilsongoncalo.mp
Hello everyone!
I'm new to C++ and i'm trying to use std::sort function to sort a vector of Solutions.
The code is something like this (solution list is a *vector):
void SolutionSet::sort(Comparator &comparator) {
std::sort(solutionsList_->begin(), solutionsList_->end(), &comparator::compare);
}
The comparator param is a Comparator´s child class instance , and the compare method is virtual at Comparator class and implemented by all Comparator's child classes.
And i want to use that function as a comparator function at std:sort().
Is this possible?
If it is, can someone tell me how? Because with the previous code, it doesn't work.
If i've not made myself clear, please just ask!
Thank you guys!