J
John B
If I have the following classes:
public abstract class Base
{
public abstract T CreateItem<T>() where T : Base;
}
public class Derived : Base
{
public override T CreateItem<T>()
{
return new Derived(); //Implicit cast error
}
}
Why does the CreateItem method in Derived fail as Derived inherits from
Base and therefore I would have thought the constraints satisfied.
If I try and explicit cast to T it fails with the error "Cannot convert
type Derived to T"
The only way it compiles is if I cast using the as operator.
Cheers
JB
public abstract class Base
{
public abstract T CreateItem<T>() where T : Base;
}
public class Derived : Base
{
public override T CreateItem<T>()
{
return new Derived(); //Implicit cast error
}
}
Why does the CreateItem method in Derived fail as Derived inherits from
Base and therefore I would have thought the constraints satisfied.
If I try and explicit cast to T it fails with the error "Cannot convert
type Derived to T"
The only way it compiles is if I cast using the as operator.
Cheers
JB