-
Notifications
You must be signed in to change notification settings - Fork 0
/
32.5.6_Multipath-Inheritance.cpp
77 lines (65 loc) · 1.94 KB
/
32.5.6_Multipath-Inheritance.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//* Multipath Inheritance.
//* Visualization link:- https://excalidraw.com/#json=JknxgwFYRsCuUN1gsIt9P,7mnZvPrgvCOcT3WJm7eeXQ
#include <iostream>
#include <string>
using namespace std;
class Human
{
public:
string name;
int age;
void display()
{
cout << "My name is " << name << endl;
}
};
//* virtual keyword is used when we want to recognize multiple same value as only one unique value, means it consider only one value from multiple values.
class Engineer : public virtual Human
{
public:
string specialization;
void specialist()
{
cout << "I have specialized in " << specialization << " field.\n";
}
};
class YouTuber : public virtual Human
{
public:
string channelName;
int subscriber;
void channelDetails()
{
cout << "My channel name is " << channelName;
cout << ", & I have " << subscriber << " subscriber on my youtube channel.\n";
}
};
class CodingTeacher : public Engineer, public YouTuber
{
public:
string techStack;
CodingTeacher(string name, string specialization, string channelName, int subscriber, string techStack)
{
//* In this two name attributes are present one from Engineer & another from YouTuber. & it also have two display().
this->name = name;
this->specialization = specialization;
this->channelName = channelName;
this->subscriber = subscriber;
this->techStack = techStack;
}
void techDetails()
{
//* We can call the function from parent class because they are in public and this class treat those as an public. In this type of problem we use virtual keyword.
specialist();
channelDetails();
cout << "I will teach you " << techStack << endl;
}
};
int main()
{
system("clear");
CodingTeacher T1("Madhur", "Computer Science Engineering", "DevFlux", 100000, "Full Stack MERN Web Development");
T1.display();
T1.techDetails();
return 0;
}