my assignment in school requires me to build an abstract class for virtual operator overloads, and then a class that makes it work. Specifically: IComparable - the abstract
class IComparable{
public:
virtual bool operator== (const IComparable&) const = 0;
virtual bool operator< (const IComparable&) const = 0;
virtual bool operator> (const IComparable&) const = 0;
virtual bool operator!= (const IComparable&) const = 0;
virtual bool operator<= (const IComparable&) const = 0;
virtual bool operator>= (const IComparable&) const = 0;
};
and Date - the actual class
class Date : public IPrintable, IComparable {
private:
int day;
int month;
int year;
public:
Date(int, int, int);
void setDay(int);
void setMonth(int);
void setYear(int);
bool Comparison(const Date&, const Date&) const;
bool larger(const Date&, const Date&) const;
bool operator== (const IComparable& other)const override;
bool operator< (const IComparable& other)const override;
bool operator> (const IComparable& other)const override;
bool operator!= (const IComparable& other)const override;
bool operator<= (const IComparable& other)const override;
bool operator>= (const IComparable& other)const override;
~Date();
};
The problem appears when i try and implement it in Date.cpp
I dont really know how to.
I thought i was supposed to use dynamic_cast to downcast a IComparable into Date to use in functions. however i run into problems with that. I Tried a few different implementations and im gonna toss them here, just in case one of them was somewhere close to what i have to do.
bool Date::operator< (const IComparable& other)const override {
Date *D1 = dynamic_cast<Date*>(other);
return(larger(*this,*D1);
}
bool Date::operator> (const IComparable& other)const override{
return(larger(other, *this));
}
bool Date::operator!= (const IComparable& other)const {
bool Flip;
Flip = Comparison(*this, other);
return(!Flip);
}
Do i need to type override? Because it shows up as an error "expected a {"
And overall, what am i doing wrong. Thanks in advance.