2016-09-22 88 views
0

我在这段代码上得到一个错误,我无法弄清楚如何纠正它。具有参数构造函数的基类的继承

public Track(string sKind, string tName, string loc, 
         string cName, string aSeason, 
         int numPlayed, int numWins, int numPlayers) 
     : base(sKind, tName, loc, cName, aSeason, numPlayed, numWins) 
    { 
     numOfPlayers = numPlayers; 
    } 

这是错误:

CS7036 There is no argument given that corresponds to the required formal parameter 'numPlayers' of 'Football.Football(string, string, string, string, string, int, int, int)' Track

我传递与调幅参数为基类的构造函数。

+2

'base()'有8个参数,你传递的只是7个。 – Sinatr

+0

你是否在''base(...',或者你实例化Track()'的那一行上得到那个错误? –

+1

你应该考虑重构你的代码,以减少构造函数参数的数量。最佳实践建议不超过3 –

回答

1

只是为了您的通话添加numPlayers到基构造函数:

: base(sKind, tName, loc, cName, aSeason, numPlayed, numWins, numPlayers) 

(请注意,您的基本构造函数需要8个参数(5串/ 3 INT),但你只有经过7(5串/ 2 INT))。

+0

谢谢!!!修复它! – LindaS