Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Can not modify Value when it's an array. #75

Closed
Lunewcome opened this issue Sep 7, 2016 · 1 comment
Closed

Can not modify Value when it's an array. #75

Lunewcome opened this issue Sep 7, 2016 · 1 comment

Comments

@Lunewcome
Copy link

The copy constructor in json11.h is like this : "const Value & operator[](size_t i) const"
So user can not update an array by "[]", for example : obj["array"][0] = a_json_value;
Why is it designed like this?

@artwyman
Copy link
Contributor

artwyman commented Sep 9, 2016

The Json type is intended to be an immutable value type, which has a number of advantages including thread safety and the ability to share data across copies. If you want a mutable array you can use a Json::array (which is just a typedef for a vector) and mutate it freely before putting it into a Json object.

@artwyman artwyman closed this as completed Sep 9, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants