specify the type of the field in the derived class

Inheritance implies an is-a relationship. Rectangle3d is not 2d, so it should probably not inherit from Rectangle2d

That said, If you must do this I suggest you use generics

public abstract class Transform<T>
{
    protected T transform;
}

public class Rectangle2d : Transform<Transform2> {}
public class Rectangle3d : Transform<Transform3> {}

In this model both 2d and 3d have a property transform which is strongly typed.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top