-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path53abstractbaseclass.cpp
More file actions
45 lines (38 loc) · 934 Bytes
/
Copy path53abstractbaseclass.cpp
File metadata and controls
45 lines (38 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
ABSTRACT BASE CLASS, WHAT IS IT?
ANS :- A CODE USING CLASSES WHICH HAS ATLEAST ONE PURE VIRTUAL FUNCTION IN A BASE CLASS, THAT CLASS IS CALLED AN
"ABSTRACT BASE CLASS".
What is a pure virtual function?
ans :- below
*/
#include <iostream>
using namespace std;
class a
{
protected:
int x;
public:
a() : x(4) {}
/*virtual void display() {}*/
// When this is activated, in the absence of derived function this will be fetched
//PURE VIRTUAL FUNCTION
virtual void display() = 0;
// When this is activated, in the absence of derived function, it will throw error as this is a "pure virtual function" and is never involved
};
class b : public a{
int y;
public:
b() : y(3){}
void display()
{
cout<<"Derived class, data a and b "<<x<<" and "<<y<<endl;
}
};
int main()
{
a * ptr;
b obj;
ptr = &obj;
ptr->display();
return 0;
}