diff --git a/src/json.cc b/src/json.cc index 31d709cb..2d67f81e 100644 --- a/src/json.cc +++ b/src/json.cc @@ -442,7 +442,7 @@ json::object_t json::get() const } } -json::operator const std::string() const +json::operator std::string() const { return get(); } diff --git a/src/json.h b/src/json.h index cb158bcc..9fe4beb2 100644 --- a/src/json.h +++ b/src/json.h @@ -175,7 +175,7 @@ class json T get() const; /// implicit conversion to string representation - operator const std::string() const; + operator std::string() const; /// implicit conversion to integer (only for numbers) operator int() const; /// implicit conversion to double (only for numbers) diff --git a/test/json_unit.cc b/test/json_unit.cc index 542eb436..63c955d1 100644 --- a/test/json_unit.cc +++ b/test/json_unit.cc @@ -773,6 +773,7 @@ TEST_CASE("string") CHECK_NOTHROW(auto v = j.get()); CHECK_THROWS_AS(auto v = j.get(), std::logic_error); CHECK_NOTHROW(auto v = j.get()); + CHECK_NOTHROW(auto v = static_cast(j)); CHECK_THROWS_AS(auto v = j.get(), std::logic_error); CHECK_THROWS_AS(auto v = j.get(), std::logic_error); CHECK_THROWS_AS(auto v = j.get(), std::logic_error);