class Eq
{
public:
virtual bool operator==(Eq operand) = 0;
};
class Day : public Eq
{
public:
enum DAY
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
} day;
Day(DAY init_day) : day(init_day){}
bool operator==(Day operand)
{
return day == operand.day;
}
};
int main()
{
Day d1(Day::Monday);
Day d2(Day::Monday);
d1 == d2;
return 0;
}
This is the code which I trying to implement. Class Eq works like as interface of JAVA. It has only one member function, operator==. Operator== takes one operand which is same type with the class which is deriving Eq class. For example, class Day derives Eq, so it have to implement operator== which is taking Day type parameter.
And there is the problem. First, both operator== functions have different signatures. So the compiler thinks they are not same functions, but overrided functions. Second, if any function in this code takes Eq class parameter, then compiler makes error because instance of the abstract class is not available.
So this is the question. How can I make operator== function in T class to take T class parameter, where T is implementation of Eq class?