blob: 1b2ffc9f5f6aed8448789f2524bb84c5a2065c30 (
plain)
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
|
//============================================================================
// Author : Sven Göthel
// Copyright : 2022 Göthel Software e.K.
// License : MIT
// Description : C++ Lesson 2.3 OOP (inheritance w/ virtual function call in ctor/dtor)
//============================================================================
#include <iostream>
#include<iostream>
using namespace std;
class base_base_dog {
public:
base_base_dog()
{
cout<< "base_dog::ctor begin" <<endl;
bark() ; //NOLINT(clang-analyzer-optin.cplusplus.VirtualCall): intentional
cout<< "base_dog::ctor end" <<endl;
}
virtual ~base_base_dog()
{
cout<< "base_dog::dtor begin" <<endl;
bark(); //NOLINT(clang-analyzer-optin.cplusplus.VirtualCall): intentional
cout<< "base_dog::dtor end" <<endl;
}
virtual void bark()
{
cout<< "base_dog::bark" <<endl;
}
};
class top_dog : public base_base_dog {
public:
top_dog()
{
cout<< "top_dog::ctor begin" <<endl;
bark(); //NOLINT(clang-analyzer-optin.cplusplus.VirtualCall): intentional
cout<< "top_dog::ctor end" <<endl;
}
~top_dog() override
{
cout<< "top_dog::dtor" <<endl;
bark(); //NOLINT(clang-analyzer-optin.cplusplus.VirtualCall): intentional
cout<< "top_dog::end" <<endl;
}
void bark() override
{
cout<< "top_dog::bark" <<endl;
}
};
int main()
{
{
cout<< "Main: Init" <<endl;
top_dog d;
cout<< "Main: top_dog created" <<endl;
d.bark();
cout<< "Main: top_dog to be dtor'ed" <<endl;
}
cout<< "Main: Done" <<endl;
}
|