123456789101112131415161718192021222324252627282930313233343536373839
#include<iostream> #include<string> using namespace std; class Mammal { public: Mammal():itsAge(1) { cout << "Mammal constructor...\n"; } ~Mammal() { cout << "Mammal destructor...\n"; } void Move() const { cout << "Mammal move one step\n"; } virtual void Speak() const { cout << "Mammal speak!\n"; } virtual void WagTail(); protected: int itsAge; }; class Dog : public Mammal{ public: Dog() { cout << "Dog Constructor...\n"; } ~Dog() { cout << "Dog destructor...\n"; } virtual void WagTail() { cout << "Wagging Tail...\n"; } virtual void Speak()const { cout << "Woof!\n"; } void Move()const { cout << "Dog moves 5 steps...\n"; } }; int main() { Mammal *pDog = new Dog; pDog->WagTail(); pDog->Speak(); system("pause"); return 0; }
virtual void WagTail(){}