-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.cc
92 lines (67 loc) · 1.28 KB
/
main.cc
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <cstdlib>
class I {
public:
I() = default;
virtual ~I() = default;
};
class C: public virtual I {
public:
C() = default;
~C() override = default;
};
class V: public virtual C {
public:
V() = default;
~V() override = default;
};
class B: public virtual I {
public:
B() = default;
~B() override = default;
};
class R: public B {
public:
R() = default;
~R() override = default;
};
class A: public R,
public virtual C
{
public:
A() = default;
~A() override = default;
};
class H: public A {
public:
H() = default;
~H() override = default;
};
class W: public H {
public:
W() = default;
~W() override = default;
};
class S: public W,
public V
{
public:
S() = default;
~S() override = default;
};
int main() {
S s;
I* i = &s;
B* b = &s;
R* r = &s;
A* a = &s;
H* h = &s;
W* w = &s;
assert(dynamic_cast<C*>(i) != nullptr); // TRUE
assert(dynamic_cast<C*>(b) != nullptr); // TRUE
assert(dynamic_cast<C*>(r) != nullptr); // TRUE
assert(dynamic_cast<C*>(a) != nullptr); // TRUE
assert(dynamic_cast<C*>(h) != nullptr); // TRUE
assert(dynamic_cast<C*>(w) != nullptr); // TRUE
return EXIT_SUCCESS;
}