I'm trying to sort an STL vector. If I write:
where:
it works. But if I try to make the predicate objLess a class method:
then it won't compile (under g++). The errors start off:
error: no matching function for call to `sort(__gnu:cxx:__normal_iterator<Foo*,std::vector<Foo, std:allocator<Foo> > >, _gnu_cxx::__normal_iterator<Foo*, std::vector<Foo, std::allocator<Foo> > >, <unresolved overloaded function type>)'
note: candidates are: void std::sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx:__normal_iterator<Foo*, std::vector<Foo, std::allocator<Foo> > >, _Compare = bool (MyClass::*)(const Foo&, const Foo&)]
Somone suggested name-mangling might be involved, but I can't figure this out. What's going on here?
Regards,
Mike
Code:
[COLOR="Blue"]sort(vec.begin(), vec.end(), objLess);[/COLOR]
where:
Code:
[COLOR="Blue"]bool objLess(const Foo& left, const Foo& right){
bool result = fooCompare();
return result;
}[/COLOR]
it works. But if I try to make the predicate objLess a class method:
Code:
[COLOR="blue"]bool MyClass::objLess(const Foo& left, const Foo& right) {...}[/COLOR]
then it won't compile (under g++). The errors start off:
error: no matching function for call to `sort(__gnu:cxx:__normal_iterator<Foo*,std::vector<Foo, std:allocator<Foo> > >, _gnu_cxx::__normal_iterator<Foo*, std::vector<Foo, std::allocator<Foo> > >, <unresolved overloaded function type>)'
note: candidates are: void std::sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx:__normal_iterator<Foo*, std::vector<Foo, std::allocator<Foo> > >, _Compare = bool (MyClass::*)(const Foo&, const Foo&)]
Somone suggested name-mangling might be involved, but I can't figure this out. What's going on here?
Regards,
Mike