基類:無法從 '參考文獻[繼承]' 轉換爲 '參考文獻[基本]' 的功能
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
到titfortat_strategy
僅繼承的函數,並且必須更改參數的內部狀態,因此ref
。 如果需要更多信息,請發表評論,我會盡我所能提供。
將其更改爲使其完美工作。謝謝。 – Sky