Question

I have a base class like the following.

TMakerObject = class
...
public
    method Clone:TControlObject; virtual; abstract;
end;

I want to make the method clone abstract. So, base class doesn't need to implement or define this method. However, the subclasses can define their own clone method.

But Compiler keep giving me this error - non-abstract class does not provide implementation for abstract method.

If so, then how is this done?

Thanks,

Était-ce utile?

La solution

(this isn't specific to Delphi) By saying the method is abstract you are saying that the base class does not define an implementation for it. So there are two options for how the language might behave:

  • You're allowed to have the base class as non-abstract, and calls to this method on an instance of the base class fail at execution time with an error along the lines of 'method not implemented'; or
  • You're not allowed to have a class contain an abstract method unless it itself is also declared abstract, so that instances of it can't exist, and the above problem never happens.

Favouring compile-time problems over execution-time ones, the language designers went with the second option.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top