为什么以下代码编译,即使我将对象传递给std::string
需要(到库)对象的显式构造函数?我的理解是不会因为关键字而被隐式转换。是否可以更改我的代码,使其仅在通过 a 时才能编译成功?nlohmann::json
std::string
explicit
nlohmann::json
我在调试模式下使用 Visual Studio 2019 和/Wall
.
#include <nlohmann/json.hpp>
struct A {
explicit A(nlohmann::json json) {
}
};
int main() {
std::string a = "hello";
A b(a);
}