-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPureVirtualCall2.cpp
71 lines (58 loc) · 1.34 KB
/
PureVirtualCall2.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
/**
* \file PureVirtualCall2.cpp
* \brief WITH PVC exception
*
* \see https://www.youtube.com/watch?v=7g8HufwNa0g&t=974s
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
struct A
{
A()
{
STD_TRACE_FUNC;
test();
}
virtual ~A()
{
STD_TRACE_FUNC;
}
void test() const
{
STD_TRACE_FUNC;
foo(); // <-- pure virtual method called
}
virtual void foo() const = 0;
};
//--------------------------------------------------------------------------------------------------
struct B :
A
{
void foo() const override
{
STD_TRACE_FUNC;
}
};
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
try {
B b;
}
catch (const std::exception &a_ex) {
std::cout << STD_TRACE_VAR(a_ex.what()) << std::endl;
}
catch (...) {
std::cout << "exception - unknown" << std::endl;
}
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
::: A :::
::: test :::
pure virtual method called
terminate called without an active exception
#endif