Сдесь мы перегрузим операцию сравнения.
Для примера возьмем операцию (<) , в результате получиться следущее...
//------------------------------------------------------------------------------------------------
#include <iostream>
#include <conio.h>
using namespace std;
class Distance
{
private:
int feet;
float inch;
public:
Distance (): feet(0), inch(0.0)
{}
Distance (int f, float i): feet(f), inch(i)
{}
void geting()
{
cout<<"Enter kol-vo feet: "; cin>>feet;
cout<<"Enter kol-vo inch: "; cin>>inch;
}
void display()
{cout<<feet<<' '<<inch<<endl;}
bool operator<(Distance) const;
};
////////////////////////////////////////////////
bool Distance::operator<(Distance obj2) const
{
float fm1=feet+inch/12;
float fm2=obj2.feet+obj2.inch/12;
return (fm1<fm2) ? true : false ; //Используем условную
операцию!
}
/////////////////////////////////////////////////
int main()
{
Distance eng1;
Distance eng2(12, 3.5);
eng1.geting();
cout<<"eng1 = "; eng1.display();
cout<<"eng2 = "; eng2. display();
if(eng1<eng2)
cout<<"eng1<eng2";
else
cout<<"eng1 > eng2";
getch();
return 0;
}
//------------------------------------------------------------------------------------------------