Hello,
i am having trouble to use the sort() function of a list<>.
I cannot seem to overload the operator<().
The variables to compare are references, like
Item* itemA;
Item* itemB;
when comparing "itemA < itemB" my overloaded function isnt called. When
the variables are defined;
Item itemA;
Item itemB;
the overloaded function is called.
I hope it is possible for what i want.
Below is my "operator<" , also a "const diritem& rhs" didnt resolve my
problem.
int diritem::operat or<(const diritem* rhs) const {
printf("%s < %s\n",this->_filename.c_st r(), rhs->_filename.c_st r());
if ((this->_type==DT_DI R) && (rhs->_type!=DT_DIR) ) {
return 1;
}
if ((this->_type!=DT_DI R) && (rhs->_type==DT_DIR) ) {
return 0;
}
return (this->_filename < rhs->_filename);
}
Any pointers are welcome!
Kind regards,
Bas Nedermeijer
i am having trouble to use the sort() function of a list<>.
I cannot seem to overload the operator<().
The variables to compare are references, like
Item* itemA;
Item* itemB;
when comparing "itemA < itemB" my overloaded function isnt called. When
the variables are defined;
Item itemA;
Item itemB;
the overloaded function is called.
I hope it is possible for what i want.
Below is my "operator<" , also a "const diritem& rhs" didnt resolve my
problem.
int diritem::operat or<(const diritem* rhs) const {
printf("%s < %s\n",this->_filename.c_st r(), rhs->_filename.c_st r());
if ((this->_type==DT_DI R) && (rhs->_type!=DT_DIR) ) {
return 1;
}
if ((this->_type!=DT_DI R) && (rhs->_type==DT_DIR) ) {
return 0;
}
return (this->_filename < rhs->_filename);
}
Any pointers are welcome!
Kind regards,
Bas Nedermeijer
Comment