Virtual methods as Comp function to sort

Posted by wilsongoncalo.mp on Stack Overflow See other posts from Stack Overflow or by wilsongoncalo.mp
Published on 2010-04-26T15:02:47Z Indexed on 2010/04/26 16:03 UTC
Read the original article Hit count: 183

Filed under:
|
|

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!

© Stack Overflow or respective owner

Related posts about c++

Related posts about comparison