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

Define classes and objects, Classes and Objects A class is a vehicle to...

Classes and Objects A class is a vehicle to execute the OOP features in the C++ language. Once a class is declared, an object of that type can be explained. An object is said t

Online tutor, Given an char variable last that has been initialized to a lo...

Given an char variable last that has been initialized to a lowercase letter, write a loop that displays all possible combinations of two letters in the range ''a'' through last. Th

Example program of c programming, Write a c program to determine interchang...

Write a c program to determine interchanged values between two variables?[Hint - if loop] What will be the output of the program? How many times this loop will execute? Wr

Minimum Shelf, At a shop of marbles, packs of marbles are prepared. Packets...

At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with thes

How the compiler arranges the several sections , Q: How the compiler arrang...

Q: How the compiler arranges the several sections in the executable image? A: The executable contained following sections: 1.      Data Section (initialized data variable sec

What does extern "c" int func(int *, A: This will turn o_ "name mangling" f...

A: This will turn o_ "name mangling" for func so that one can connect to code compiled by a C compiler.

C program for maximum no, C Program for MAXIMUM NO, MINIMUM NO AND SORTING ...

C Program for MAXIMUM NO, MINIMUM NO AND SORTING   void main() {           int i,j,t;           int a[5];           clrscr();           for(i=0;i

#calculate percentge, #write a multilevel c++ program to take marks of 3 su...

#write a multilevel c++ program to take marks of 3 subjects and calculate percentage and display it

Simple generic version of method isequalto, Write a simple generic version ...

Write a simple generic version of method isEqualTo that compares its two arguments with the equals method and returns true if they are equal and false otherwise. Use this generic m

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