forked from leonardodiasc/P6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist6602.cpp
49 lines (40 loc) · 1.03 KB
/
list6602.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
#include <iostream>
#include <string>
using namespace std;
class visible {
public:
visible(string&& msg) : msg_{move(msg)} {cout << msg_ << '\n'; }
string const& msg() const { return msg_; }
private:
string msg_;
};
class base1 : virtual public visible {
public:
base1(int x) : visible{"base1 constructed"}, value_{x} {}
int value() const { return value_;}
private:
int value_;
};
class base2 : virtual public visible {
public:
base2(string const& str) : visible{"base2{" + str + "} constructed"} {}
};
class base3 : virtual public visible {
public:
base3() : visible{"base3 constructed"} {}
int value() const { return 42; }
};
class derived : public base1, public base2, public base3 {
public:
derived(int i, string const& str)
: base3{}, base2{str}, base1{}, visible{"derived"}
{}
int value() const { return base1::value() + base3::value(); }
string msg() const {
return base1::msg() + "\n" + base2::msg() + "\n" + base3::msg();
}
};
int main () {
derived d{42, "example"};
cout << d.value() << '\n' << d.msg() << '\n';
}