小编Lun*_*rap的帖子

我不明白为什么这个构造函数不起作用

我有一个简单FiniteStateMachine,并为FSM的状态是从继承的类FSMState抽象类,至极的力量实现的某些方法和字段,该ownerClass字段是一个泛型类型,所以每个国家持有到拥有该实例的类的引用密克罗尼西亚联邦

public abstract class FSMState<T>
{
    /// <summary>
    /// Reference to the owner class of this State.
    /// </summary>
    protected abstract T ownerClass { get; set; }
    /// <summary>
    /// The ID name of this State.
    /// </summary>
    public abstract string Name { get; set; }

    //Constructor
    public FSMState(T owner, string name)
    {
        ownerClass = owner;
        Name = name;
    }
}
Run Code Online (Sandbox Code Playgroud)

所以州级会看起来像这样

public class MovingState : FSMState<AI>
{
    protected override AI ownerClass { get; set; } …
Run Code Online (Sandbox Code Playgroud)

c# generics inheritance constructor abstract-class

1
推荐指数
1
解决办法
117
查看次数

标签 统计

abstract-class ×1

c# ×1

constructor ×1

generics ×1

inheritance ×1