G
Guest
The methods within an interface is not virtual.
How do I go about doing the following:
class BaseClass : IComparable
{
int CompareTo(Object o) {...}
};
class DerivedClass : BasedClass
{
// compiler won't allow this since CompareTo is not virtual
int CompareTo(Object o) {...}
};
void foo()
{
DerivedClass d1 = new DerivedClass();
DerivedClass d2 = new DerivedClass();
...
b1 = d1;
b2 = d2;
BaseClass b1, b2;
b1.CompareTo(b2); // ideally, would like DerivedClass's CompareTo
to be invoked
}
A solution I can think of is to write my own IComparable class and make the
functions virtual. Thanks.
How do I go about doing the following:
class BaseClass : IComparable
{
int CompareTo(Object o) {...}
};
class DerivedClass : BasedClass
{
// compiler won't allow this since CompareTo is not virtual
int CompareTo(Object o) {...}
};
void foo()
{
DerivedClass d1 = new DerivedClass();
DerivedClass d2 = new DerivedClass();
...
b1 = d1;
b2 = d2;
BaseClass b1, b2;
b1.CompareTo(b2); // ideally, would like DerivedClass's CompareTo
to be invoked
}
A solution I can think of is to write my own IComparable class and make the
functions virtual. Thanks.