-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain02.cpp
More file actions
80 lines (66 loc) · 1.85 KB
/
Copy pathmain02.cpp
File metadata and controls
80 lines (66 loc) · 1.85 KB
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
#include <iostream>
using std::cin, std::cout, std::endl;
class ZC1
{
private:
int x, y;
public:
ZC1(int x_ = 0, int y_ = 0) : x(x_ + 3), y(y_ + 3) { cout << "call ZC1(int: " << x_ << "," << y_ << "): (" << x << "," << y << ")" << endl; }
ZC1(const ZC1 &z1) : x(z1.x + 5), y(z1.y + 5) { cout << "call ZC1(ZC1 &:" << z1.x << "," << z1.y << "): (" << x << "," << y << ")" << endl; }
ZC1 &operator=(const ZC1 &z1);
int sum(int z);
void hf1(ZC1 &z1) {cout << "call ZC1::hf1(ZC1&: " << z1.x << "," << z1.y << ")" << endl;}
void hf2(ZC1 z1) {cout << "call ZC1::hf2(ZC1: " << z1.x << "," << z1.y << ")" << endl;}
ZC1 hf3();
};
ZC1 &ZC1::operator=(const ZC1 &z1)
{
x = z1.x + 7;
y = z1.y + 7;
cout << "call &operator=(ZC1 &" << z1.x << "," << z1.y << "): (" << x << "," << y << ")" << endl;
return *this;
}
int ZC1::sum(int z = 11)
{
cout << "call ZC1::sum(int " << z << ")" << endl;
return x + y + z;
}
ZC1 ZC1::hf3()
{
cout << "call ZC1::hf3()" << endl;
return *this;
}
int main()
{
cout << endl
<< "test basic_class" << endl;
ZC1 z1 = 2;
cout << endl;
cout << "sizeof(z1): " << sizeof(z1) << endl;
cout << "sizeof(int): " << sizeof(3) << endl;
cout << endl;
ZC1 *pz1 = &z1;
cout << "ZC1* -> sum(): " << pz1->sum() << endl;
cout << "(*ZC1*).sum(): " << (*pz1).sum() << endl;
ZC1 &rz1 = z1;
cout << "ZC1& .sum(): " << rz1.sum() << endl;
cout << "ZC1(3, 5).sum(7): " << ZC1(3, 5).sum(7) << endl;
cout << endl;
z1 = 13;
cout << endl;
z1.hf1(z1);
cout << endl;
z1.hf2(z1);
cout << endl;
ZC1 Z2(z1.hf3());
cout << endl;
ZC1 z3[3] = {3, 5, ZC1(7, 11)};
cout << endl;
ZC1 *z4[2] = {new ZC1(), new ZC1(3, 5)};
delete z4[0];
delete z4[1];
ZC1 *z5 = new ZC1[2];
delete z5;
cout << endl;
return 0;
}