-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox.cpp
More file actions
113 lines (90 loc) · 1.96 KB
/
Copy pathbox.cpp
File metadata and controls
113 lines (90 loc) · 1.96 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "box.h"
#include <iostream>
#include <exception>
/*
//s06
// Box::Box(int _W, int _H, int _L){ // constructor
// L = _L;
// W = _W;
// H = _H;
// }
// Box::Box() // default constructor
// {
// L = W = H = 0;
// }
// Box::Box(int _W)
// {
// W = _W;
// L = H = 0;
// }
Box::Box(int _W, int _H, int _L) : L {_L}, W{_W}, H{_H}
{
}
Box::Box(int _W) : Box {_W, 0, 0}
{
}
Box::Box() : Box {0} // default constructor
{
}
void Box::disp(){
std::cout << L << " " << W << " " << H << std::endl;
}
*/
// s07
Box::Box(int _L, int _W, int _H) : L {_L}, W{_W}, H{_H}
{
std::cout << this << " contructor 3 member variable" << std::endl;
m_count++;
}
Box::Box(int _L) : Box {_L, 0, 0}
{
std::cout << "contructor 1 member variable" << std::endl;
m_count++;
}
Box::Box() : Box {0} // default constructor
{
std::cout << " default contructor 3 member variable" << std::endl;
m_count++;
}
Box::Box(const Box& b)
{
std::cout << "copy constructor" << std::endl;
L = b.L;
W = b.W;
H = b.H;
m_count++;
}
Box::~Box(){
std::cout << "destructor: I am dying ..." << std::endl;
m_count--;
}
void Box::disp() const{
std::cout << L << " " << W << " " << H << std::endl;
}
Box* Box::setW(int _W)
{
if(_W >= 0)
W = _W;
else
// throw new std::invalid_argument{ "W error" };
std::cerr << "W should be bigger than 0" << std::endl;
return this;
}
Box* Box::setH(int _H)
{
if(_H >= 0)
H = _H;
else
// throw new std::invalid_argument{ "W error" };
std::cerr << "H should be bigger than 0" << std::endl;
return this;
}
Box* Box::setL(int _L)
{
if(_L >= 0)
L = _L;
else
// throw new std::invalid_argument{ "W error" };
std::cerr << "L should be bigger than 0" << std::endl;
return this;
}