I want to implement a generic interval class that stores two IComparable objects corresponding to the bottom and top of the interval. However, I want to be able to pool different types of Intervals together (perhaps in a collection), so I need to inherit my generic class from a general interval class. This is what I have so far:

public ref class Interval abstract
{
public:
virtual property Object^ Lo {
Object^ get() = 0;
}

virtual property Object^ Hi {
Object^ get() = 0;
}
};

generic<typename T> where T:Object public ref class IntervalGen : Interval
{
protected:
T _lo;
T _hi;

public:

virtual property T Lo {
T get() override { return _lo; }
void set(T value) { _lo = value; }
}

virtual property T Hi {
T get() override { return _hi; }
void set(T value) { _hi = value; }
}

};

This doesn't compile, due to the error:

'T IntervalGen<T>::Hi::get(void)': overriding virtual function return type differs from 'System::Object ^Interval::Hi::get(void)'

and a similar error for the Lo parameter. Semantically, there's no reason this shouldn't be possible; T is constrained to be an object, so it's simply covariant return types. However, I've never seen an example of covariant return types with generics. Is this possible?

Also, I'm not sure about the syntax to constrain T to be an object and be IComparable. Could someone give me a pointer on that?

Thanks,
Eric