-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathmain.cpp
70 lines (53 loc) · 1.58 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
#include "shape.hpp"
#include "rectangle.hpp"
#include "circle.hpp"
#include "qassert.h" // for Q_ASSERT
Q_DEFINE_THIS_FILE // file name for assertions
Shape s1(1, 2); // static allocation
Rectangle r1(1, 2, 15, 10); // static allocation
std::uint32_t a;
Circle c1(3, 4, 10); // static allocation
int main(void) {
Shape s2(3, 4); // automatic allocation
Shape *ps3 = new Shape(5, 6); // dynamic allocation
//Shape const *ps1 = &s1; // const pointer to s1
Shape *ps = &r1; // automatic upcasting!
r1.draw(); // early binding
ps->draw(); // late binding
a = ps->area();
Shape const *graph[] = {
&c1,
&r1,
ps3,
(Shape *)0
};
drawGraph(graph); // <== drawGraph() operation
s1.moveBy(7, 8);
s2.moveBy(9, 10);
ps3->moveBy(-1, -2);
//ps1->moveBy(-3, -4);
r1.draw();
a = r1.area();
r1.moveBy(7, 8);
Q_ASSERT(r1.distanceFrom(&r1) == 0U);
Q_ASSERT(s1.distanceFrom(&s1) == 0U);
Q_ASSERT(s1.distanceFrom(&s2) ==
s2.distanceFrom(&s1));
Q_ASSERT(s1.distanceFrom(&s2) <=
s1.distanceFrom(ps3)
+ ps3->distanceFrom(&s2));
delete ps3;
while (1) {
}
//return 0; // unreachable code
}
//............................................................................
extern "C" {
void Q_onAssert(char const *module, int loc) {
// TBD: damage control
(void)module; // avoid the "unused parameter" compiler warning
(void)loc; // avoid the "unused parameter" compiler warning
while (1) { // hang in an endless loop
}
}
} // extern "C"