I'm having trouble sorting STL. I am trying to sort an object vector by a data member in an object. I looked through a few examples, but as soon as it gets into my configuration, it somehow does not compile under GCC. I tested Visual Studio and it works. I get this error in GCC:
no match for call to '(test::by_sym) (const stock&, const stock&)
I do not understand that the same code will be compiled in Visual Studio.
Here is my setup.
driver.cpp
DB t1;
t1.print();
cout << "---sorting---" << endl;
t1.sSort();
t1.print();
DB class
vector<stock> list;
struct by_sym {
bool operator()(stock &a, stock &b) {
return a.getSymbol() < b.getSymbol();
}
};
void DB::sSort(){
std::sort(list.begin(), list.end(), by_sym());
}
and my stock class only has data items.
Is there any way around GCC?
I believe my question is similar to this , but the solutions there do not work for me.
source
share