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 are the two types of polymorphism?

589


Why do we use using namespace std in c++?

597


Why is standard template library used?

577


Explain the scope of resolution operator.

624


Define namespace in c++?

646






Does c++ have string data type?

689


How do you establish an is-a relationship?

616


How do c++ struct differs from the c++ class?

588


What are static type checking?

625


What is ifstream c++?

554


Define pure virtual function?

559


What is purpose of abstract class?

582


How should a contructor handle a failure?

683


How can I learn c++ easily?

618


What is the two main roles of operating system?

510