i'm having trouble using the overloaded operator< in a method(menorTamanhoque()) of my derived class.
i have the base class here:
class CAngulo
{
protected:
int grau, minutos, segundos;
public:
CAngulo(void);
CAngulo(int g,int m, int s);
CAngulo(const CAngulo &p);
bool operator< (const CAngulo &p);
};
CAngulo :: CAngulo(void)
{
grau=10;
minutos=5;
segundos=15;
}
CAngulo :: CAngulo(int g, int m ,int s)
{
grau=g;
minutos=m;
segundos=s;
}
CAngulo :: CAngulo(const CAngulo &p)
{
grau=p.grau;
minutos=p.minutos;
segundos=p.segundos;
}
bool CAngulo :: operator < (const CAngulo &p)
{
if(grau>p.grau)
return(false);
else if(grau<p.grau)
return(true);
else if(grau==p.grau)
{
if(minutos>p.minutos) return(false);
else if(minutos<p.minutos) return(true);
else if(minutos==p.minutos)
{
if(segundos>p.segundos) return(false);
else return(true);
}
}
}
and here i have the derived class where i want to use the overloaded operator above:
class CSetor : public CAngulo
{
private:
int raio;
public:
CSetor(void);
CSetor(int g,int m, int s, int r);
CSetor(const CSetor &p);
bool menorTamanhoQue(const CSetor &a);
};
CSetor :: CSetor(void)
{
grau=10;
minutos=5;
segundos=15;
raio=10;
}
CSetor :: CSetor(int g, int m ,int s, int r)
{
grau=g;
minutos=m;
segundos=s;
raio=r;
}
CSetor :: CSetor(const CSetor &p)
{
grau=p.grau;
minutos=p.minutos;
segundos=p.segundos;
raio=p.raio;
}
bool CSetor :: menorTamanhoQue(const CSetor &a)
{
}
Dont know how to implement the last method menorTamanhoque (i have to use the oveloaded < to compare c and d and check if this->raio < a.raio)
here is the main so you guys can understant what the program does:
int main()
{
CAngulo a(10,10,10);
CAngulo b(20,20,20);
CSetor c(10,20,30,5);
CSetor d(20,40,40,15);
if(a < b) cout<<"a e menor que b"<<endl;
else cout<<"a e maior que b"<<endl;
if(c.menorTamanhoQue(d)) cout<<"c e menor que d"<<endl;
else cout<<"c e maior que d"<<endl;
}
First off, your declaration of menhorTamanhoQue
takes 2 arguments, but the definition takes one.
The declaration should be
bool menorTamanhoQue(const CSetor &a);
and then the definition should be
bool CSetor::menorTamanhoQue(const CSetor &a)
{
return this->CAngulo::operator<(a) // explicitly call base class operator<
&& this->raio < a.raio; // and check raio
}
Here's a demo.