Pure Virtual Function And Abstract Class In C++
Sometimes
implementation of all function cannot be provided in a base class because we
don’t know the implementation.
A pure
virtual function (or abstract function) in C++ is a
virtual function for which we don’t have
implementation, we only declare it. A pure virtual function is declared by
assigning 0 in declaration.
Fig: Pure Virtual Function And Abstract Class In C++
Syntax:
class base class
{
----
------
public:
virtual return type
functionname(argument)=0;
};
Program:
#include<iostream.h>
#include<conio.h>
Class BCA
{
public:
virtual void get()=0;
};
class MCA: public BCA
{
public:
int a;
void get()
{
cout<<”input one
no”;
cin>>a;
cout<<a;
}
};
void main()
{
MCA a2;
a2.get();
getch();
}
Output:
Input one no 76
76
No comments:
Post a Comment