diff --git a/include/json/value.h b/include/json/value.h index a60ca8f..b7cebb4 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -171,7 +171,7 @@ private: CZString(const char* cstr, DuplicationPolicy allocate); CZString(const CZString& other); ~CZString(); - CZString& operator=(CZString other); + CZString &operator=(const CZString &other); bool operator<(const CZString& other) const; bool operator==(const CZString& other) const; ArrayIndex index() const; @@ -238,7 +238,7 @@ Json::Value obj_value(Json::objectValue); // {} Value(const Value& other); ~Value(); - Value& operator=(Value other); + Value &operator=(const Value &other); /// Swap values. /// \note Currently, comments are intentionally not swapped, for /// both logic and efficiency. diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 2a0b97b..18d89b2 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -188,8 +188,9 @@ void Value::CZString::swap(CZString& other) { std::swap(index_, other.index_); } -Value::CZString& Value::CZString::operator=(CZString other) { - swap(other); +Value::CZString &Value::CZString::operator=(const CZString &other) { + CZString temp(other); + swap(temp); return *this; } @@ -478,8 +479,9 @@ Value::~Value() { delete[] comments_; } -Value& Value::operator=(Value other) { - swap(other); +Value &Value::operator=(const Value &other) { + Value temp(other); + swap(temp); return *this; }