Construire un objet avec new et paramètre dans un template
Bonjour,
J'aimerais construire un objet dynamiquement dans un template, tout en lui passant des paramètres.
Avec T pour template :
Code:
1 2 3 4
|
void construct(nlohmann::json& json) {
T* obj = new T(json);
} |
Retourne :
Citation:
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);
Alors que ceci :
Citation:
nlohmann::json j("Data/Ressources/Tile.json");
Tile* t = new Tile(j["none"]);
compile sans soucis.
Je ne comprend pas pourquoi, merci de votre aide !