13.10 END OF CHAPTER PROGRAMS

13.10.1 A class with virtual function can be instantiated

Problem: Write a program to demonstrate the following:

  1. A class with virtual function can be instantiated. Such virtual function can also be executed.
  2. With virtual function in the base class, derived class object executes the function of its own class.

Solution: In addition to normal solution, let us add some movement to the output. Let us move characters on the screen to symbolize movement. With different speeds! See Program 13.6.

Program 13.6 Moving output

// vbase3.cpp#include<<iostream.h>#include<<string.h>#include<<conio.h>void delay(long N) ; // function prototype class Creatures  { public:        char name[40];        Creatures(char *p) ;        virtual ...

Get Object Oriented Programming with C++, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.