-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
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
Casting to std::string not working in VS2015 #861
Comments
Could you try the following? s1 = o["name"].get<std::string>(); |
That works. However, I think the other way should be made to work, too. |
Is the error message showing something about If so, this is a known issue, unfortunately this a C++ problem, see this doc section for more details |
The error message is in my original post. operator= is not mentioned. json o = { { "name", "value" } };
static_cast<std::string>(o["name"]); // Failing line |
Here is the output on GCC, which is more helpful:
It's the same issue basically, since the json object has a conversion operator for every type, the compiler does not know which one it should call. One workaround is to use I don't think we can do anything more about it unfortunately. |
So why this compiles in VS, if the condition and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value is included for When you compiled with GCC, did you explicitly exclude this condition (as it is only excluded if _MSC_VER is defined, which shouldn't be the case for GCC)? If no, VS and GCC are behaving diffrently here. Nevertheless I do not understand the behavior. I thought that the compiler would use the |
I haven't touched the library code when I compiled your code. As to why the constructor is called, cppreference will be more clear and accurate than me. |
Any idea how to move forward here? |
On MSVC 2017 the implicit cast to string doesn't work due a C++ issue, so I fix it following the JSON library usage. Reference: https://github.com/nlohmann/json#basic-usage nlohmann/json#861
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
The following doesn't compile in Visual Studio 2015 Update 3:
It gives the following error:
I tried this with the develop branch aswell as the 2.1.1 release.
I'm using Visual Studio 2015 Update 3 with compiler version 19.00.24215.1 for x86
This is related to #188 and #167. I have to exclude the _MSC_VER check, so that the condition included in the VS build, too. However, this condition has been introduced to fix #167 as far as I understand. Was #167 a problem in VS2015 pre Update 3 only, or hasn't a test been added for #167? I can compile and run all unit-xxx tests with the check removed.
The text was updated successfully, but these errors were encountered: