What is Pure Virtual Function? Why and when it is used ?

Answer Posted / mahfuzur rahman

Virtual function vs pure virtual function :

Virtual function :-

1. Virtual function have a function body.
2. Overloaded can be done by the virtual funciton.
(Optional)
3. It is define as : virtual int myfunction();


Pure virtual function :-

1. Pure virtual function have no function body.
2. Overloading is must in pure virtual funciton. (Must)
3. It is define as : virtual int myfunction() = 0;
4. A class is "abstract class" when it has at least one
pure virtual function.
5. You cann't create instance of "abstract class", rather
you have to inherit the "abstract class" and overload all
pure virtual function.

Like :- CControlBar class is an "abstract class".

Is This Answer Correct ?    144 Yes 24 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is size of string in c++?

555


Write a program using display() function which takes two arguments.

611


Is swift faster than go?

616


Explain about vectors in c ++?

598


What operator is used to access a struct through a pointer a) >> b) -> c) *

596






Explain container class.

689


How do you invoke a base member function from a derived class in which you have not overridden that function?

584


What are destructors?

575


What is flush () in c++?

579


What do you mean by “this” pointer?

619


What is the difference between while and do while loop?

558


What is binary object model?

602


What is the use of bit fields in structure declaration?

544


Do you need a main function in c++?

561


Which software is best for programming?

663