-
Notifications
You must be signed in to change notification settings - Fork 0
/
32.5.3_Multiple-Inheritance.cpp
65 lines (55 loc) · 1.82 KB
/
32.5.3_Multiple-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
//* Multiple Inheritance.
//* Visualization link:- https://excalidraw.com/#json=37N2qgeUR5H5q5HGv7gA3,QnHhLbhp2Giyol9hGx3aYQ
#include <iostream>
#include <string>
using namespace std;
class Engineer
{
public:
string name;
string specialization;
void specialist()
{
cout << "My name is " << name;
cout << ", & I have specialized in " << specialization << " field.\n";
}
};
class YouTuber
{
public:
string channelName;
int subscriber;
void channelDetails()
{
cout << "My channel name is " << channelName;
cout << ", & I have " << subscriber << " subscriber on my youtube channel.\n";
}
};
//* Here firstly Engineer class default constructor will be called & than YouTuber class constructor will be called & at last CodingTeacher constructor will be called. Because we firstly inherit Engineer class & than we inherit YouTuber class, if we interchange this than order of constructor calling will be also change.
class CodingTeacher : public Engineer, public YouTuber
{
public:
string techStack;
CodingTeacher(string name, string specialization, string channelName, int subscriber, string techStack)
{
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.
specialist();
channelDetails();
cout << "I will teach you " << techStack << endl;
}
};
int main()
{
system("clear");
CodingTeacher T1("Madhur", "Computer Science", "DevFlux", 8000000, "Full Stack MERN Web Development & React Native App Development");
T1.techDetails();
return 0;
}