我有一个简单的FiniteStateMachine,FSM的状态是继承自const char* output = "Test";
const size_t len = strlen(output) + 1;
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len);
memcpy(GlobalLock(hMem), output, len);
GlobalUnlock(hMem);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_TEXT, hMem);
CloseClipboard();
抽象类的类,它强制实现某些方法和字段,FSMState
字段是泛型类型,所以每个州都拥有对拥有FSM实例的类的引用
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;
}
}
但是构造函数不起作用,我得到了这两个错误
错误CS7036没有给出与FSMState.FSMState所需的形式参数所有者对应的参数(AI,字符串)
错误:类型FSMState不包含带0参数的构造函数
我不知道是否可以这样做,我希望继承表单public class MovingState : FSMState<AI>
{
protected override AI ownerClass { get; set; }
public override string Name { get; set; }
//Contructor.
public MovingState(AI owner, string name)
{
ownerClass = owner;
Name = name;
}
}
的类实现一个构造函数来设置字段FSMState
和Name
,但是{{1 }}字段必须是通用的
我正在尝试做一些不可能的事情?
答案 0 :(得分:9)
您需要在MovingState
中调用基类构造函数:
public MovingState(AI owner, string name)
: base(owner, name)
{
}