Before I ask my question, I apologize for the crude outlook of my program; I tried to use the code tags on here, but, for some inconceivable reason, they would not work! Same goes for the other formatting tools on here. Even the text editor would not even generate a 'preview' of my post on clicking on the Preview button!! This was not the performance before though; I confess I've not been using this Forum a lot of recent.
Now to my question:
Does anyone know why the compiler keeps flagging my use of the STL's sort function in the program below?
void printMientos (list<spanishWord>& m)
{
for (list<spanishWord>::iterator iter = m.begin(); iter != m.end(); iter++)
cout<<(*iter).spaWord<<" "<<(*iter).engWord<<endl;
}
Shown below are the error messages I got from the compiler:
C:\Dev-Cpp\include\c++\3.4.2\bits\list.tcc In member function `void std::list<_Tp, _Alloc>::merge(std::list<_Tp, _Alloc>&) [with _Tp = spanishWord, _Alloc = std::allocator<spanishWord>]':
30 C:\Users\Kolly\Desktop\mientos1.cpp instantiated from here
221 C:\Dev-Cpp\include\c++\3.4.2\bits\list.tcc no match for 'operator<' in '(&__first2)->std::_List_iterator<_Tp>::operator* [with _Tp = spanishWord]() < (&__first1)->std::_List_iterator<_Tp>::operator* [with _Tp = spanishWord]()'
@MiiNiPaa:
Just to clarify, the sort() function I'm using is a member function of the std::list class. It appears the std::sort function you are referring to is a global (generic) function. Mine is similar to the example below, culled from one of the pages on this site (http://www.cplusplus.com/reference/list/list/sort/)
The sort function is not the problem; you have not defined a way to compare two spanishWord objects in your original example. The sort function will, unless you provide it with an alternative, try to use the less-than operator (<) to compare them, which you will want to define for your class if you want it to work.