- A class containing the pure virtual function cannot be used to declare the objects of its own, such classes are known as abstract base classes.
- Pure virtual function can be defined as:
- virtual void show() = 0;
#include <iostream>
using namespace std;
class A
{
public:
virtual void show()=0;
};
class B: public A
{
public:
void show()
{
cout<<"India"<<endl;
}
};
int main() {
A *a;
B b;
a = &b;
a->show();
// A a1; Error
//A *a2=new A; Error
return 0;
}
No comments:
Post a Comment