我试图通过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'等等。 –