I have:
std::vector< QPointer<ToDoItem> > items;
and the call to sort:
std::sort(items.begin(), items.end(), custComparFunction)
I am using the custom sorting function:
bool ToDoList::custComparFunc(QPointer<ToDoItem> i1, QPointer<ToDoItem> i2){
if (i1.data()->getSecsTillDeadline() == i2.data()->getSecsTillDeadline()){
return i1.data()->getMainText() < i2.data()->getMainText();
}
return i1.data()->getSecsTillDeadline() < i2.data()->getSecsTillDeadline();
}
I am trying to sort a vector of QPointers based on the value returned by 'getSecsTillDeadline()' function
but I am getting the error 'must use '.*' or '->*' to call pointer to member function'.
where am I going wrong? the error is in a file predefined_ops.h so I would imagine that there is something in my own code I can change to make this work
the full error is:
C:\Qt\Tools\mingw492_32\i686-w64-mingw32\include\c++\bits\predefined_ops.h:121: error: must use '.*' or '->*' to call pointer-to-member function in '((__gnu_cxx::__ops::_Iter_comp_iter<bool (ToDoList::*)(QPointer<ToDoItem>, QPointer<ToDoItem>)>*)this)->__gnu_cxx::__ops::_Iter_comp_iter<bool (ToDoList::*)(QPointer<ToDoItem>, QPointer<ToDoItem>)>::_M_comp (...)', e.g. '(... ->* ((__gnu_cxx::__ops::_Iter_comp_iter<bool (ToDoList::*)(QPointer<ToDoItem>, QPointer<ToDoItem>)>*)this)->__gnu_cxx::__ops::_Iter_comp_iter<bool (ToDoList::*)(QPointer<ToDoItem>, QPointer<ToDoItem>)>::_M_comp) (...)'
{ return bool(_M_comp(*__it1, *__it2)); }
^
It seems form the error message that custComparFunction
is a non-static member function in the ToDoItem
class. You can't use non-static member functions like "normal" non-member function pointers.
The simplest solution is to make the function a static
member function.