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
Describe public access specifiers?
What is ios in c++?
Which bit wise operator is suitable for putting on a particular bit in a number?
What happens when the extern "c" char func (char*,waste) executes?
How would you obtain segment and offset addresses from a far address of a memory location?
What is the full form nasa?
What is the best it certification?
Is it legal in c++ to overload operator++ so that it decrements a value in your class?
Is swift better than c++?
Why do we use pointers in c++?
What is the difference between equal to (==) and assignment operator (=)?
What does the ios::ate argument do?
What is a set in c++?
Does c++ have finally?
How to declare a pointer to an array of integers?