基类:
abstract class Base_strategy
{
public Base_strategy()
{
EnemyLastTurn = Choices.NULL;
score = 0;
}
static public void compare(ref Base_strategy player1, ref Base_strategy player2)
{
/* stuff */
}
abstract protected Choices firstTurn();
abstract protected Choices defectedLastTurn();
abstract protected Choices cooperatedLastTurn();
protected Choices EnemyLastTurn;
public int score;
public abstract void addScore_Sucker();
public abstract void addScore_Traitor();
public abstract void addScore_Punishment();
public abstract void addScore_Reward();
}
继承类:
class titfortat_strategy : Base_strategy
{
titfortat_strategy()
{
}
/* overridden functions */
}
代码:
titfortat_strategy p1, p2;
Base_strategy.compare(ref p1, ref p2);
错误是Argument 1: cannot convert from 'ref titfortat_strategy' to 'ref Base_strategy'
Argument 2: cannot convert from 'ref titfortat_strategy' to 'ref Base_strategy'
我不确定为什么它不起作用。看起来它应该,虽然......compare()
调用仅从Base_strategy
to继承的函数titfortat_strategy
,并且必须更改参数的内部状态,因此ref
. 如果需要更多信息,请发表评论,我会尽力提供。