Sorry, I posted this in the Beginners forum, but I think it may not be such a beginner topic(?). Please advise if Beginners forum is the right place for this.
Hi there. I'm trying to sort a vector with a custom sort method. I cannot seem to figure out the correct syntax to use std::sort() with the third parameter, since I am trying to do this within class methods, and not my main.cpp file.
Edit: here's the error I'm getting:
error: must use '.*' or '->*' to call pointer-to-member function
Here's what I have:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include "SpreadSheet.h"
bool SpreadSheet::sortMethod(Sortable* a, Sortable* b)
{
return a->value() > b->value();
}
void SpreadSheet::sortLinesBy(std::string categoryName)
{
//m_categories[categoryName] returns an std::vector<Sortable*>
std::vector<Sortable*> newVector = m_categories[categoryName];
std::sort(newVector.begin(), newVector.end(), sortSortablesMethod);
}
I have learned through my exploration of the internet that I am dealing with function pointers. I don't quite understand the examples people have posted, but all of them seem to be a bit different than mine anyway.