Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Animal
- {
- public:
- Animal();
- Animal(string name, int limbs);
- string Name;
- int Limbs;
- void Description();
- };
- class Dog : public Animal
- {
- public:
- Dog();
- Dog(string name, int limbs);
- };
- int main()
- {
- // "An ANIMAL is born!" IS NOT CALLED
- // "I am a Spot with 4 limbs." IS PRINTED
- Dog dog("Spot", 4);
- system("pause");
- }
- Animal::Animal()
- {
- cout << "An ANIMAL is born!" << endl;
- Name = "Default";
- Limbs = 2;
- }
- Animal::Animal(string name, int limbs) :
- Name(name), Limbs(limbs)
- {
- // Additional stuff could be executed here.
- }
- void Animal::Description()
- {
- cout << endl;
- cout << "I am a " << Name << " with " << Limbs << " limbs." << endl;
- cout << endl;
- }
- Dog::Dog()
- {
- cout << "A DOG is born!" << endl;
- }
- // In the event we don't want the empty parent,
- // Animal() constructor to be called:
- Dog::Dog(string name, int limbs) : Animal(name, limbs)
- {
- Name = name;
- Limbs = limbs;
- Description();
- }
Advertisement
Add Comment
Please, Sign In to add comment