pure virtual functionsan abstract class is one


Pure Virtual Functions

An abstract class is one, which is used just for deriving some other classes. No object of this class is declared and used in the program. Likewise, there are pure virtual functions which themselves won't be used. Consider the above example with some changes.

class Shape

                 {

                  public :

virtual void print() = 0; // Pure virtual

                             function

                 };

                class Triangle : public Shape

                 {

                  public :

void print()

 {

                cout << " I am a Triangle " << endl;

 }

 };

class  Circle : public Shape

                 {

                  public :

void print()

 {

                cout << " I am a  Circle " << endl;

 }

                 };

 

 

 

void main()

 {

  Shape S;

  Triangle T;

  Circle C;

 

                  Shape *ptr;

 

                                ptr = &T;

                                ptr -> print();

 

ptr = &C;

                                ptr -> print();

                }

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: pure virtual functionsan abstract class is one
Reference No:- TGS0309461

Expected delivery within 24 Hours