简体   繁体   中英

Does not implement inherited abstract member error, but base class does implement

Getting a compile error in C# saying that my child class does not implement an inherited abstract data member.

Structure is essentially this:

public abstract class Transaction
{
    public abstract int MyMethod();
}

public abstract class GeneralTransaction : Transaction
{
    public override int MyMethod()
    {
        return 1;
    }
}

public class SpecificTransaction : GeneralTransaction
{
}

It is saying that SpecificTransaction is not implementing MyMethod, but why does it have to? The GeneralTransaction class implements it and the SpecificTransaction class inherits from that class?

I'm affraid that youre structure is more complicated than this. This example works just fine.

class Program
{
    static void Main(string[] args)
    {
        var tr = new SpecificTransaction();
        Console.WriteLine(tr.MyMethod()); //shows 1
    }
}

public abstract class Transaction
{
    public abstract int MyMethod();
}

public abstract class GeneralTransaction : Transaction
{
    public override int MyMethod()
    {
        return 1;
    }
}

public class SpecificTransaction : GeneralTransaction
{
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM