i am trying to use some of the algorithms in STL , and i have problems making my class "STL-compliant". I defined the proper operators, but i get compile errors i am not able to get past when i try to use sort. any ideas about what i am making wrong?
Code:#include <algorithm> #include <vector.h> class IPoint { public : float energ,x,y,z; char nume[10]; IPoint(); //no arg constructor IPoint(const IPoint& m); //copy constructor const IPoint& operator=(const IPoint& right); //copy assignment operator IPoint(float, float, float, float, char*); void Set(float, float, float, float, char*); bool operator==( const IPoint& right) ; //== operator bool operator!=(const IPoint& right) ; //!= operator bool operator<(const IPoint& right) ; //< operator bool operator>(const IPoint& right) ; //> operator }; IPoint::IPoint() { Set(0,0,0,0,"defname"); } IPoint::IPoint(float en,float vx,float vy, float vz,char* a) { Set(en,vx,vy,vz,a); } void IPoint::Set(float en,float vx,float vy, float vz,char *vnume) { energ=en; x=vx; y=vy; z=vz; strcpy(nume,vnume); } IPoint::IPoint(const IPoint& p ){ energ=p.energ; x=p.x; y=p.y; z=p.z; strcpy(nume,p.nume); }; const IPoint& IPoint::operator=(const IPoint& right){ if(this!=&right){ IPoint(right); }; return *this; }; bool IPoint::operator==( const IPoint& right){ return (energ == right.energ); }; bool IPoint::operator!=(const IPoint& right){ return (energ!=right.energ); }; bool IPoint::operator>(const IPoint& right){ return (energ>right.energ); }; bool IPoint::operator<(const IPoint& right){ return (energ<right.energ); }; int main(){ vector<IPoint> vect; IPoint pct; pct.Set(100,0,0,0,"1"); vect.push_back(pct); pct.Set(150,0,0,0,"1"); vect.push_back(pct); pct.Set(250,0,0,0,"2"); vect.push_back(pct); if (vect[0]<vect[1]) cout<<"0<1"<<endl; sort(vect.begin(),vect.end()); };



LinkBack URL
About LinkBacks


