我試圖通過C++繼承,我的代碼有問題。我有從它派生的基類Caine和CaineCuPete。我在聲明派生類構造函數時遇到錯誤。基類變量'未在其範圍內聲明'
CaineCuPete(int nPete) : Caine(cNume,cHeight,cWeight,cAge,cColor);
錯誤:
cNume was not declared in its scope. cHeight was not declared in its scope. ...
我試圖通過C++繼承,我的代碼有問題。我有從它派生的基類Caine和CaineCuPete。我在聲明派生類構造函數時遇到錯誤。基類變量'未在其範圍內聲明'
CaineCuPete(int nPete) : Caine(cNume,cHeight,cWeight,cAge,cColor);
錯誤:
cNume was not declared in its scope. cHeight was not declared in its scope. ...
您需要將這些作爲輸入參數在您的派生類構造函數中。
CaineCuPete(int nPete, string cNume, double cHeight,
double cWeight, double cAge, int cColor) : Caine(cNume,cHeight,cWeight,cAge,cColor),
Pete (nPete)
{
}
此鏈接解釋: http://www.learncpp.com/cpp-tutorial/114-constructors-and-initialization-of-derived-classes/
你需要在你的派生類的構造函數把這些作爲輸入參數。 –
請提供一個[SSCCE](http://sscce.org),因爲人們只能猜測'cNume'等等。 –