I have a base that is inherited twice. The second subclass doesn’t provide any signature for the method clone, but the third subclass does and defines the method clone as follows.
TControlObject = abstract class
...
public
method Clone:TControlObject; virtual; abstract;
end;
TGateControl = class(TControlObject)
...
public
...
end;
TAndControl = class(TGateControl)
public
method Clone:TControlObject; override;
end;
However, compiler raises an error that TGateControl class doesn’t provide implementation for clone method. Since TGateControl is inherited from TControlObject and TAndControl class is inherited from TGateControl, the method clone should automatically be overridden for the base class clone method. Am I right?
Thanks in advance,
You have the
abstractattribute on the Clone method inTControlObject. This means that any class that directly derives fromTControlObjectmust provide an implementation of the Clone method (see MSDN abstract). As a result TGateControl must provide an implementation of Clone. IfTControlObjecthad a concrete implementation of Clone then, yes, it would not need to be overridden.So some options are to:
abstractattribute on clone.Clonein eitherTControlObjectorTGateControl.And to clarify, these methods are never “automatically overridden”. The derived class is able to call the base class’ implementation but it would be incorrect to say that the derived class has “automatically overridden” the base class’ implementation.