Michel Keijzers
Michel Keijzers

Reputation: 15357

Error in enum returning function in interface with generic type

I think the code says more than a complete description:

public interface IBank
{
    Bank.EType Type { get; }
}


public abstract Bank<T>: ...
{
    public enum EType { Int, Gm, User };

    private EType _type;

    public EType Type { get { return _type; } }
}

I get the error:

Using the generic type PcgTools.Mmodel.Common.Synth.Bank requires type arguments

How should I define the prototype in the interface to get no errors?

Upvotes: 1

Views: 87

Answers (1)

Lee
Lee

Reputation: 144126

As the error suggests, the Bank class requires type arguments which you have not supplied. You could choose a type for T e.g.

Bank<string>.EType Type { get; }

but this probably isn't what you want since this would defeat the purpose of making Bank generic in the first place.

The types Bank<int>.EType and Bank<string>.EType are different types and cannot be compared, so you should move it into a non-generic class or to the top level:

public abstract class Bank
{
    public enum EType { Int, Gm, User };
}

public abstract class Bank<T> : Bank
{
}

Upvotes: 4

Related Questions