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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.