不实现继承的抽象成员 [英] Does not implement inherited abstract member
问题描述
嗨
我有一个抽象类
Hi
I have a abstract class
public abstract class Service
{
public abstract void DoWork();
}
和子课程
and sub classes are
public class Updater : Service
{
}
和
and
public class Sweeper : Service
{
public string Path
{
get;
set;
}
public int DaysToKeep
{
get;
set;
}
}
但是当我想构建项目时它会给我一个错误:
but when I want to build the project it give me an error :
'MyService.Sweeper' does not implement inherited abstract member 'MultiPurposeService.Service.DoWork() '
我尝试了什么:
解决了这个错误:
不实现继承的抽象成员
What I have tried:
solve this error :
does not implement inherited abstract member
推荐答案
有时候阅读错误的文档可能是个好主意...
Reading the error's documentation can be good idea sometimes...
需要一个类来实现所有摘要基类中的成员,除非该类也是抽象的。
A class is required to implement all the abstract members in the base class, unless the class is also abstract.
如果你问自己为什么......抽象方法根据定义没有实现, howev呃,现在你创建了一个新类 - Sweeper - 它已经(继承)了一个方法 - DoWork。
当你打电话给Sweeper.DoWork时会发生什么?有些混乱,因为根本没有实现该方法。因此,链中的第一个非抽象类必须实现方法...
And if you ask yourself why... Abstract methods has no implementation by definition, however, now you created a new class - Sweeper - which has (inherited) a method - DoWork.
What should happen when you call Sweeper.DoWork? Some mess, as there is no implementation at all to that method. Therefore, the first non-abstract class in the chain must implement the method...
这篇关于不实现继承的抽象成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!