Explain pure virtual functions, C/C++ Programming

Assignment Help:

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();

                }

 


Related Discussions:- Explain pure virtual functions

Change to palindrome, A palindrome is a string that reads the same from bot...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Explain about the expressions in c language, Explain about the Expressions ...

Explain about the Expressions in c Language? An expression is the combination of constants, variables and operators arranged as per the syntax of the language. Some of the illu

Arrays, #question.Write a c++ program to accept and print a 1_d array

#question.Write a c++ program to accept and print a 1_d array

Pro, i need to do my home work

i need to do my home work

A client and a server for an instant messaging system based , Develop a cli...

Develop a client and a server for an instant messaging system based on UDP and IPv4

What are the different types of endless loops, What are the different types...

What are the different types of endless loops? An endless loop can be of two types: i.) A loop that is intentionally designed to go round and round until the condition withi

Named what can derived class add?, New data members  New member function...

New data members  New member functions  New constructors and destructor  New friends

Prepare invoice ocr and document management, Project Description: We are...

Project Description: We are seeking online invoice OCR solution. That will help us to automate accounts payable function. User should be able to use the offered pdf file or s

Described multiple inheritance(virtual inheritance)?, Described multiple in...

Described multiple inheritance(virtual inheritance)? And explain its advantages and disadvantages? A: It is the procedure in which a child can be derived from more than one pare

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd