-
Notifications
You must be signed in to change notification settings - Fork 0
/
oo.cpp
84 lines (67 loc) · 1.32 KB
/
oo.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
// Copyright 2016 Carnegie Mellon University. See LICENSE file for terms.
#include <iostream>
#include "oohelper.hpp"
class Cls1 {
public:
int x;
char y;
DEFINE_PRINT_CONSTRUCTOR(Cls1);
DEFINE_PRINT_DESTRUCTOR(Cls1);
DEFINE_PRINT_OPERATOR_DELETE(Cls1);
virtual void func1() {
std::cout << "Cls1::func1()" << std::endl;
}
void func2() {
std::cout << "Cls1::func2()" << std::endl;
}
};
struct Str1 {
int x,y;
char s[50];
};
class Cls2 {
public:
struct Str1 s;
int z;
DEFINE_PRINT_CONSTRUCTOR(Cls2);
DEFINE_PRINT_DESTRUCTOR(Cls2);
DEFINE_PRINT_OPERATOR_DELETE(Cls2);
virtual void func3() {
std::cout << "Cls2::func3()" << std::endl;
}
virtual void func4() {
std::cout << "Cls2::func4()" << std::endl;
}
};
class Cls3 : public Cls1, public Cls2 {
public:
int i;
Cls3() {
PRINT_CONSTRUCTOR_NAME(Cls3);
i = 42;
}
DEFINE_PRINT_DESTRUCTOR(Cls3);
DEFINE_PRINT_OPERATOR_DELETE(Cls3);
virtual void func1() {
std::cout << "Cls3::func1()" << std::endl;
}
virtual void func3() {
std::cout << "Cls3::func3()" << std::endl;
}
};
void myfunc() {
Cls3 *e = new Cls3();
Cls1 *f = new Cls3();
Cls1 *c1 = new Cls1();
c1->func2();
e->func1();
e->func3();
e->func4();
f->func1();
delete e;
delete f;
delete c1;
}
int main() {
myfunc();
}