-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.cpp
100 lines (81 loc) · 1.47 KB
/
main.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
struct Interface
{
virtual void Foo(int param = -1) = 0;
// Clang-Tidy: Default arguments on virtual or override methods are prohibited
};
class Abstract
: public Interface
{
public:
void Foo(int param) override
{
std::cout << "Abstract = " << param << std::endl;
}
};
class Base
: public Abstract
{
public:
void Foo(int param = 1) override
{
std::cout << "Base = " << param << std::endl;
}
};
class Impl
: public Base
{
public:
void Foo(int param) override
{
std::cout << "Impl = " << param << std::endl;
}
};
class Concrete
: public Impl
{
public:
void Foo(int param = 3) override
{
std::cout << "Concrete = " << param << std::endl;
}
};
void test1()
{
std::cout << "Concrete" << std::endl;
Concrete concrete;
concrete.Foo();
std::cout << std::endl;
std::cout << "Impl" << std::endl;
Impl& impl = concrete;
impl.Foo(2);
std::cout << std::endl;
std::cout << "Base" << std::endl;
Base& base = impl;
base.Foo();
std::cout << std::endl;
std::cout << "Abstract" << std::endl;
Abstract& abstract = base;
abstract.Foo(0);
std::cout << std::endl;
std::cout << "Interface" << std::endl;
Interface& interface = abstract;
interface.Foo();
}
/*
Concrete
Concrete = 3
Impl
Concrete = 2
Base
Concrete = 1
Abstract
Concrete = 0
Interface
Concrete = -1
*/
int main()
{
test1();
return 0;
}