Code
Code
return 0;
// Method to make sound
}
virtual void makeSound() {
std::cout << name << " makes a
sound." << std::endl;
}
Explanation:
// Method to get the name
Base Class (Animal):
std::string getName() {
return name;
Contains a protected member variable
}
name to store the name of the animal.
};
Has a constructor to initialize the
name.
};