6
6
// Test1: simple object
7
7
8
8
struct Student {
9
+ Student () : name(), age(), height(), canSwim() {}
10
+ Student (const std::string name, unsigned age, double height, bool canSwim) :
11
+ name (name), age(age), height(height), canSwim(canSwim)
12
+ {}
13
+
9
14
std::string name;
10
15
unsigned age;
11
16
double height;
@@ -31,7 +36,7 @@ void test1() {
31
36
32
37
// Serialize
33
38
{
34
- Student s = { " Lua" , 9 , 150.5 , true } ;
39
+ Student s ( " Lua" , 9 , 150.5 , true ) ;
35
40
36
41
JsonWriter writer;
37
42
writer & s;
@@ -54,6 +59,7 @@ void test1() {
54
59
// You can map a JSON array to other data structures as well
55
60
56
61
struct Group {
62
+ Group () : groupName(), students() {}
57
63
std::string groupName;
58
64
std::vector<Student> students;
59
65
};
@@ -124,7 +130,7 @@ class Shape {
124
130
virtual void Print (std::ostream& os) const = 0;
125
131
126
132
protected:
127
- Shape () {}
133
+ Shape () : x_(), y_() {}
128
134
Shape (double x, double y) : x_(x), y_(y) {}
129
135
130
136
template <typename Archiver>
@@ -142,7 +148,7 @@ Archiver& operator&(Archiver& ar, Shape& s) {
142
148
143
149
class Circle : public Shape {
144
150
public:
145
- Circle () {}
151
+ Circle () : radius_() {}
146
152
Circle (double x, double y, double radius) : Shape(x, y), radius_(radius) {}
147
153
~Circle () {}
148
154
@@ -168,7 +174,7 @@ Archiver& operator&(Archiver& ar, Circle& c) {
168
174
169
175
class Box : public Shape {
170
176
public:
171
- Box () {}
177
+ Box () : width_(), height_() {}
172
178
Box (double x, double y, double width, double height) : Shape(x, y), width_(width), height_(height) {}
173
179
~Box () {}
174
180
@@ -195,7 +201,7 @@ Archiver& operator&(Archiver& ar, Box& b) {
195
201
196
202
class Canvas {
197
203
public:
198
- Canvas () {}
204
+ Canvas () : shapes_() {}
199
205
~Canvas () { Clear (); }
200
206
201
207
void Clear () {
0 commit comments