Bonjour,
J'aimerais construire un objet dynamiquement dans un template, tout en lui passant des paramètres.
Avec T pour template :
Retourne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 void construct(nlohmann::json& json) { T* obj = new T(json); }
Alors que ceci :RessourceManager.hpp: In instantiation of ‘void RessourceManager<T>::construct(nlohmann::json&) [with T = Tile*; nlohmann::json = nlohmann::basic_json<>]’:
RessourceManager.hpp:18:12: required from ‘RessourceManager<T>::RessourceManager(nlohmann::json&) [with T = Tile*; nlohmann::json = nlohmann::basic_json<>]’
Manager.cpp:7:53: required from here
RessourceManager.hpp:34:22: error: cannot convert ‘nlohmann::json {aka nlohmann::basic_json<>}’ to ‘Tile*’ in initialization
T* obj = new T(json);
compile sans soucis.nlohmann::json j("Data/Ressources/Tile.json");
Tile* t = new Tile(j["none"]);
Je ne comprend pas pourquoi, merci de votre aide !
Partager