Why does the following code compile, even though I am passing a std::string
object to a explicit constructor which expects a nlohmann::json
(to the library) object? My understanding is that std::string
won't be implicit converted due to the explicit
keyword.
Is it possible to change my code so that it will compile successful only when a nlohmann::json
is passed?
I use Visual Studio 2019 in Debug Mode with /Wall
.
#include <nlohmann/json.hpp>
struct A {
explicit A(nlohmann::json json) {
}
};
int main() {
std::string a = "hello";
A b(a);
}