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
What do you mean by function pointer?
Is it possible to get the source code back from binary file?
What are libraries in c++?
What is the difference between a type-specific template friend class and a general template friend class?
What is class and structure in c++?
What is class in c++ with example?
What is a terminating character in c++?
What are arithmetic operators?
Explain Memory Allocation in C/C++ ?
What flag means?
Explain the difference between c & c++?
What is the basic structure of c++ program?
What are move semantics?
what you know about c++?
Please explain class & object in c++?