VirtualFunc

VirtualFunc - /examples of Pure virtual functions /Note...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 //examples of Pure virtual functions //Note syntax #include <iostream> using namespace std enum COLOR { Red, Green, Blue, Yellow, White, Black, Brown } class Animal // common base to both Mammal and Fish { public: Animal(int) virtual ~Animal() { cout << "Animal destructor. ..\n" } virtual int GetAge() const { return itsAge } virtual void SetAge(int age) { itsAge = age } virtual void Sleep() const = 0 virtual void Eat() const = 0 virtual void Reproduce() const = 0 virtual void Move() const = 0 virtual void Speak() const = 0 private: int itsAge } Animal::Animal(int age): itsAge(age) { cout << "Animal constructor. ..\n" } class Mammal : public Animal { public: Mammal(int age):Animal(age) { cout << "Mammal constructor. ..\n" } virtual ~Mammal() { cout << "Mammal destructor. ..\n" } virtual void Reproduce() const { cout << "Mammal reproduction depicted. ..\n" } } class Fish : public Animal { public: Fish(int age):Animal(age) { cout << "Fish constructor. ..\n" } virtual ~Fish() {cout << "Fish destructor. ..\n" } virtual void Sleep() const { cout << "fish snoring. ..\n" } virtual void Eat() const { cout << "fish feeding. ..\n" } virtual void Reproduce() const { cout << "fish laying eggs. ..\n" } virtual void Move() const { cout << "fish swimming. ..\n" }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

VirtualFunc - /examples of Pure virtual functions /Note...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online