devxlogo

vector<> members must define < and == operators

vector<> members must define < and == operators

The STL vector, as well as other standard containers, support comparison and sorting of their members by calling the corresponding standard functions found in the header file. These functions rely on the relational operators such as == and //file: Date.hclass Date { public: bool operator == (const Date& d) const { return d.Year()==year && d.Month()==month && d.Day()==day;} bool operator #include#includeusing namespace std;void main(){ Date d1, d2(1970); vector vd(10); vd.push_back(d1); vd.push_back(d2);//sort uses overloaded == and > of class Date sort(vd.begin(), vd.end());}

devx-admin

Share the Post: