From 82b5c425676d2b07e88c1a8d243ea8284cc21a1d Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Mon, 12 Feb 2018 13:14:59 +0800 Subject: [PATCH] Fix Compile error because of -Werror=effc++ is on Fix #1170 Also fixed C++03 problem for using nullptr. --- example/archiver/archiver.h | 2 +- example/archiver/archivertest.cpp | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/example/archiver/archiver.h b/example/archiver/archiver.h index 65b31a4..2150367 100644 --- a/example/archiver/archiver.h +++ b/example/archiver/archiver.h @@ -74,7 +74,7 @@ public: bool HasMember(const char* name) const; JsonReader& EndObject(); - JsonReader& StartArray(size_t* size = nullptr); + JsonReader& StartArray(size_t* size = 0); JsonReader& EndArray(); JsonReader& operator&(bool& b); diff --git a/example/archiver/archivertest.cpp b/example/archiver/archivertest.cpp index 788db36..16afa1e 100644 --- a/example/archiver/archivertest.cpp +++ b/example/archiver/archivertest.cpp @@ -6,6 +6,11 @@ // Test1: simple object struct Student { + Student() : name(), age(), height(), canSwim() {} + Student(const std::string name, unsigned age, double height, bool canSwim) : + name(name), age(age), height(height), canSwim(canSwim) + {} + std::string name; unsigned age; double height; @@ -31,7 +36,7 @@ void test1() { // Serialize { - Student s = { "Lua", 9, 150.5, true }; + Student s("Lua", 9, 150.5, true); JsonWriter writer; writer & s; @@ -54,6 +59,7 @@ void test1() { // You can map a JSON array to other data structures as well struct Group { + Group() : groupName(), students() {} std::string groupName; std::vector students; }; @@ -124,7 +130,7 @@ public: virtual void Print(std::ostream& os) const = 0; protected: - Shape() {} + Shape() : x_(), y_() {} Shape(double x, double y) : x_(x), y_(y) {} template @@ -142,7 +148,7 @@ Archiver& operator&(Archiver& ar, Shape& s) { class Circle : public Shape { public: - Circle() {} + Circle() : radius_() {} Circle(double x, double y, double radius) : Shape(x, y), radius_(radius) {} ~Circle() {} @@ -168,7 +174,7 @@ Archiver& operator&(Archiver& ar, Circle& c) { class Box : public Shape { public: - Box() {} + Box() : width_(), height_() {} Box(double x, double y, double width, double height) : Shape(x, y), width_(width), height_(height) {} ~Box() {} @@ -195,7 +201,7 @@ Archiver& operator&(Archiver& ar, Box& b) { class Canvas { public: - Canvas() {} + Canvas() : shapes_() {} ~Canvas() { Clear(); } void Clear() {