Having trouble with subclass constructor in C++?
I have a class dog there is to be a subclass of dog called a MexicanHairless with an added property of hair which is set to false (0). How do I create a constructor for MexicanHairless keep getting the error "no appropriate default constructor available."
class Dog
{ protected:
string name;
char gender;
public:
Dog (string theName, char theGender)
{ name = theName;
gender = theGender;}
~Dog ( ) { }
void bark(int n)
{ for (int i =1; i <=n; i++) cout << "rff " << endl; }
void sleep()
{ cout << "zzzz, zzzz" << endl; }
void eat()
{ cout << "slurp" << endl; }
int compare(Dog dog1, Dog dog2)
{ if (dog1.gender == dog2.gender)
if(dog1.name == dog2.name)
return 1;
return 0;
}
};
class MexicanHairlessDog : private Dog{
protected:
int hair;
MexicanHairlessDog()
{
// Here?
}
};
Having trouble with subclass constructor in C++?c++ compiler
The MexicanHairlessDog() constructor needs to call the Dog( string, char ) constructor since it is the only one. Or else you need to create a Dog() constructor in the base class.
MexicanHairlessDog() : Dog(
string("Hairless"),
'F'){
}
More Related Questions and Answers ...
The information post by website user , we not guarantee correctness.
Dental Treatment Skin Whitening Skin Problems Skin Rashes Shoes
