Pure Virtual Function - C++ - with Examples

Started by Kalyan, Jun 28, 2008, 11:49 PM

previous topic - next topic
Go Down


Pure Virtual Function - C++

A virtual function body is known as Pure Virtual Function. In above example we can see that the function is base class never gets invoked. In such type of situations we can use pure virtual functions

Example : same example can re-written
class base
virtual void show()=0; //pure virtual function

class derived1 : public base
void show()
cout<<"\n Derived 1";

class derived2 : public base
void show()
cout<<"\n Derived 2";

void main()
base *b; derived1 d1; derived2 d2;
b = &d1;
b = &d2;

Rules for Virtual Functions

1. The virtual function must be member of class
2. They cannot be static members
3. They are accessed by using object pointers
4. Prototype of base class function & derived class must be same
5. Virtual function in base class must be defined even though it is not used
6. A virtual function can be friend function of another class
7. We could not have virtual constructor
8. If a virtual function is derived in base class, it need not be necessarily redefined in the derived class
9. Pointer object of base class can point to any object of derived class but reverse is not true
10. When a base pointer points to derived class, incrementing & decrementing it will not make it point to the next object of derived class


it is very useful for my exam and also know the view of pure virtual function


Very helpful to me too. I'm learning about this language, it is hard for beginners like me. Thank you for this material.

Go Up

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Please leave this box empty:

Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

shortcuts: alt+s submit/post or alt+p preview
IT Acumens Web Designing Chennai | GinGly :: Build your Personal Website | CineBuzz :: Cinema News | My Kids Diary :: Kids Memories Writing :: Book Website @ 349 Rs monthly
Copyright 2005 - 2020 :: IT Acumens :: All Rights Reserved. :: Sitemap
ITAcumens Discussion Forum with 2 lakhs post running for 15 years - Powered by IT Acumens Dedicated Server