-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInheritance8.h
77 lines (66 loc) · 1.15 KB
/
Inheritance8.h
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
#pragma once
class MultipleInheritanceDemo
{
class Horns // ðîãà
{
protected:
string color_;
double weight_;
public:
Horns()
{
color_ = "brown";
weight_ = 20;
}
Horns(string color, double weight)
{
color_ = color;
weight_ = weight;
}
};
class Hooves // êîïûòà
{
protected:
string shape_;
int size_;
public:
Hooves()
{
shape_ = "()"; // [] <> {}
size_ = 45;
}
Hooves(string shape, int size)
{
shape_ = shape;
size_ = size;
}
};
class Elk : public Horns, public Hooves // ëîñü
{
string nick_;
public:
Elk(string nick)
{
nick_ = nick;
}
void Print() const
{
cout << "Nick: " << nick_ << "\n";
cout << "Horns color: " << color_ << "\n";
cout << "Horns weight: " << weight_ << "\n";
cout << "Hooves shape: " << shape_ << "\n";
cout << "Hooves size: " << size_ << "\n";
}
};
public:
static void Test()
{
Elk elk("Dave");
elk.Print();
// ïðàêòèêà:
// à) ïðîñëåäèòü çà âûçîâîì êîíñòðóêòîðîâ
// á) äîáàâèòü ïåðåãðóçêó êîíñòðóêòîðîâ â ëîñÿ
// â) âûçâàòü èç ïðîèçâîäíîãî êëàññà ïðîäâèíóòûå êîíñòðóêòîðû áàçîâûõ êëàññîâ
}
};
// MultipleInheritanceDemo::Test();