We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doing += with js2["key"]["num"] is an error while runtime.
+=
js2["key"]["num"]
Error message is : what(): [json.exception.type_error.308] cannot use push_back() with number
what(): [json.exception.type_error.308] cannot use push_back() with number
But it works fine with js1["num"]. Why are they different, it's against the intuition I think?
js1["num"]
And is the error message relevant with the operation we are doing?
int main() { json js1,js2; js1["num"] = 0; js2["key"]["num"] = 0; js1["num"] += 10;//fine js2["key"]["num"] += 10;//error }
The text was updated successfully, but these errors were encountered:
Already the first occurrence of += yields the same exception. The library uses operator+= as synonym of push_back, and it is not usable with numbers.
operator+=
push_back
If you want to use += with the stored integer, you need to make it explicit:
int main() { json js1,js2; js1["num"] = 0; js2["key"]["num"] = 0; js1["num"].get_ref<json::number_integer_t&>() += 10; js2["key"]["num"].get_ref<json::number_integer_t&>() += 10; std::cout << js1 << '\n' << js2 << std::endl; }
Output:
{"num":10} {"key":{"num":10}}
Sorry, something went wrong.
No branches or pull requests
Doing
+=
withjs2["key"]["num"]
is an error while runtime.Error message is :
what(): [json.exception.type_error.308] cannot use push_back() with number
But it works fine with
js1["num"]
.Why are they different, it's against the intuition I think?
And is the error message relevant with the operation we are doing?
The text was updated successfully, but these errors were encountered: