What is Pure Virtual Function? Why and when it is used ?
Answer Posted / talha bilal
Pure Virtual Function
class Base //Abstract base class
{
public:
virtual void show() = 0; //Pure Virtual Function
};
class Derived:public Base
{
public:
void show()
{
cout << "Implementation of Virtual Function in Derived class";
}
};
int main()
{
Base obj; //Compile Time Error
Base *b;
Derived d;
b = &d;
b->show();
}
Virtual Function
class Base
{
public:
virtual void show()
{
cout << "Base class";
}
};
class Derived:public Base
{
private:
void show()
{
cout << "Derived Class";
}
};
int main()
{
Base *b; //Base class pointer
Derived d; //Derived class object
b = &d;
b->show(); //Late Binding Occurs
}
Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
Can non-public members of another instance of the class be retrieved by the method of the same class?
Explain data encapsulation?
What are virtual functions in c++?
What is c++ in english?
What is difference between array and vector in c++?
What problems might the following macro bring to the application?
Which sort does c++ use?
What is isdigit c++?
an integer constant must have atleast one a) character b) digit c) decimal point
What is the main purpose of overloading operators?
What do you mean by const correctness?
How long it will take to learn c++?
How do you sort a sort function in c++ to sort in descending order?
What is atoi in c++?
What is the difference between the indirection operator and the address of oper-ator?