A pure virtual function (or abstract function) in C++ is a virtual function for which we don’t have an implementation, we only declare it. A pure virtual function is declared by assigning 0 in the declaration. We can not instantiate the abstract class and we have to define it in the derived class.
Let see the below example.
#include<iostream>
using namespace std;
class Base
{
public:
//pure virtual function
virtual void fun() = 0;
};
class Child: public Base
{
public:
void fun()
{
cout << "Child class fun is called";
}
};
int main()
{
Child d;
d.fun();
return 0;
}
Answer:
A pure virtual function (or abstract function) in C++ is a virtual function for which we don’t have an implementation, we only declare it. A pure virtual function is declared by assigning 0 in the declaration. We can not instantiate the abstract class and we have to define it in the derived class.
Let see the below example.
Output: Child class fun is called
need an explanation for this answer? contact us directly to get an explanation for this answer