-
Notifications
You must be signed in to change notification settings - Fork 0
/
29_virtualbaseclass.cpp
54 lines (54 loc) · 1.06 KB
/
29_virtualbaseclass.cpp
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
46
47
48
49
50
51
52
53
54
// Virtual base classes are used in virtual inheritance in a way of
//preventing multiple “instances” of a given class appearing in an
//inheritance hierarchy when using multiple inheritances.
#include <iostream>
using namespace std;
class student
{
protected :
int studentID;
public :
void getID(){
cout<<"enter student ID "<<endl;
cin>>studentID;
}
};
class test : virtual public student
{
protected :
int marks;
public :
void getmarks(){
cout<<"enter student marks"<<endl;
cin>>marks;
}
};
class sports : virtual public student
{
protected :
int score;
public:
void getscore(){
cout<<"enter student score "<<endl;
cin>>score;
}
};
class result : public test , public sports
{
public :
void display()
{
cout<<"ID of student is : "<<studentID<<endl;
cout<<"marks of student is : "<<marks<<endl;
cout<<"score of student is : "<<score<<endl;
}
};
int main()
{
result res;
res.getID();
res.getmarks();
res.getscore();
res.display();
return 0;
}