C++ program to implement Pure Virtual Functions

A program to demonstrate how a pure virtual function is defined, declared and invoked from the object of derived class through the pointer of the base class.


1. Start the process
2. Invoke the class with pointer
3. Assign ptr<-&obj 4. Call the ptr->getdata()
a. Get the roll no and name of the student
5. Call the ptr->display()
a. Print the roll no and name
6. Stop the process


	class  base 
		private: int x;
			float y;
		public : virtual void getdata( );
			virtual void display( );
	class dev : public base
		private:  int roll;
			 char name[20];
		public : void getdata( );
			void  display( );
	void base :: getdata( )  {  }
	void base :: display( )   {  }
	void dev :: getdata( )
		cout<<” Enter Roll of  the Student “;
		cin>> roll;
		cout<<” Enter name of  the student”;
	void dev :: display( )
		cout<<”Name is :<<name<<endl;
		cout<<” Roll no is :<<roll <<endl;
	void main( )
		base * ptr;
		dev obj;
		clrscr( );
		ptr = &obj;
		ptr -> getdata( );
		ptr -> display( );
		getch( );


Enter the roll no of the student: 111
Enter the name of the student : Kapil Dev

Name is : Kapil Dev
Roll no is : 111

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.