You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question: return static json object from function #618
assuming the first code block is in file A and the second block is in file B.
When you call save_config() from file B the function uses the config object from file A, because you do not
pass an argument to the function. The function in file A does not know about the object from file B.
There are two ways to solve this problem, depending on what you want to do.
If you want to modify the static object make get_config() return a reference.
If you want to make a copy of the static object (that is what happens now) and store it, pass it to save_config.
Activity
Bosswestfalen commentedon Jun 14, 2017
Hi,
assuming the first code block is in file A and the second block is in file B.
When you call
save_config()from file B the function uses the config object from file A, because you do notpass an argument to the function. The function in file A does not know about the object from file B.
There are two ways to solve this problem, depending on what you want to do.
If you want to modify the static object make
get_config()return a reference.If you want to make a copy of the static object (that is what happens now) and store it, pass it to
save_config.Regards,
Bosswestfalen
nlohmann commentedon Jun 16, 2017
@bdoblackfish Did this work for you?