交叉编译错误 Visual Studio C++

Cross-compilation errors Visual studio C++

本文关键字:C++ Studio Visual 错误 交叉编译      更新时间:2023-10-16

我最近将我的Windows C++应用程序转换为Linux c ++应用程序,并使用带有Debian的Windows子系统交叉编译到Linux。但是,我通过使用 nlohmann 的 json 库收到以下错误

no match for 'operator-' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<double> >::value_type {aka double}' and 'nlohmann::basic_json<>::value_type {aka nlohmann::basic_json<>}')

例如,我在 json 元素和双精度之间使用运算符的任何地方都会遇到此错误。举个例子:

MSE_total += pow(ref.z[j*multiplier] - actual[j]["z"], 2) / pow(ref.z[j*multiplier], 2);

这是给出上述错误的行。我应该明确说明 json 中的变量类型吗?我该怎么做呢?

没有

operator-采取nlohmann::basic_json。我猜那

ref.z[j*multiplier] - actual[j]["z"]

希望actual[j]["z"]通过其operator ValueType()转换为double...它应该(在底层类型不匹配的情况下抛出type_error.302(。

为什么没有?我打赌nlohmann的json版本号与Windows和Linux版本不同。

解决办法:将该值强制转换为双精度型 ( actual[j]["z"].get<double>() (。