Hello, after I have friendet my class to "<" operator it dosn't work after i use sort over an vector of class instances it does nothing:
class + main :
class RAngle{
public:
int x,y,l;
RAngle(){
}
RAngle(int i,int j,int k){
x=i,y=j,l=k;
}
bool operator<(const RAngle& rhs)const
{
if(l < rhs.l){
return true;
}
return 0;
}
friend ostream& operator << (ostream& out, const RAngle& ra){
out << ra.x << " " << ra.y << " " << ra.l <<endl;
return out;
}
friend istream& operator >>( istream& is, RAngle &ra)
{
is >> ra.x;
is >> ra.y;
is >> ra.l;
return is ;
}
};
//main:
void descrSort(vector <RAngle> &l){
sort(l.begin(),l.end());
reverse(l.begin(),l.end());
for(unsigned i=0; i<l.size();i++){ //////at print the output is the same as the input ////
cout<<l[i]<<endl;
}
}
void readData(vector <RAngle> &l){
RAngle r;
ifstream f_in;
f_in.open("ex.in",ios::in);
for(int i=0;i<10;++i){
f_in >> r;
cout << r;
l.push_back(r);
}
}
int main(){
vector <RAngle> a;
vector <RAngle> b;
readData(a);
descrSort(a);
return 0;
}
Sorry for the long post, but I'm really without ideas why doesn't it work.