0

I recently converted my Windows C++ application to a Linux c++ application and use a Windows subsystem with Debian to cross-compile to Linux. However, I get the following error by using the json library by nlohmann

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<>}')

I get this error everywhere where I use an operator between a json element and a double for example. As an example:

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

This is the line that gives the error above. Should I explicitely state what type of variable is in the json? And how do I do this?

Thomas Wagenaar
  • 6,489
  • 5
  • 30
  • 73

1 Answers1

0

There's no operator- taking a nlohmann::basic_json. I guess then that

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

expects actual[j]["z"] to be converted to double via its operator ValueType()... and it should (throwing type_error.302 in case of underlying type mismatch).

Why it doesn't? My bet is on nlohmann's json version number differing from your windows and linux builds.

Workaround: cast that value to a double (actual[j]["z"].get<double>()).

YSC
  • 38,212
  • 9
  • 96
  • 149