I am trying to map json data to a class called Game
by using the macro NLOHMANN_DEFINE_TYPE_INTRUSIVE
but I am getting the error:
error: no matching function for call to ‘nlohmann::basic_json<>::get<g::Game>()’ 19 | game = data.get<g::Game>();
This is the class:
namespace g{
class Game {
public:
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Game, _name, audience)
private:
uintptr_t _id; // unique id can act as an invitation code
uintptr_t _ownerID;
bool _started;
std::vector<Connection> _players;
std::string _name;
//Bounds of player given in json file
struct PlayerCount {
int min;
int max;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(PlayerCount, min, max)
} player_count;
bool audience;
// map of { name_string -> { configurable_value , prompt_text } }
std::map<std::string, std::pair<std::any, std::string>> setup;
std::map<std::string, List> constants;
std::map<std::string, List> variables;
std::map<std::string, List> per_player;
std::map<std::string, List> per_audience;
std::vector<Rule> rules;
};
}
The error is coming from here, specifically the get<g::Game>()
line:
using json = nlohmann::json;
using namespace g;
InterpretJson::InterpretJson(string path){
this->path = path;
ifstream f(path);
json jData = json::parse(f);
f.close();
data = jData;
}
void InterpretJson::interpret(Game& game){
game = data.get<g::Game>(); //data is private member defined in InterpretJson.h and is of type json
}
How do I fix this?