2016-09-22 102 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