vendredi 1 juillet 2016

Builder pattern, templates and nested class

I'm trying to develop a nested builder class in C++, but I keep getting this "invalid use of incomplete type 'class Npc::Builder<'T>" error. I've searched a lot and I couldn't find an answer. Can anyone help me, please? Here's my code: Npc.h class Npc{ ... template<class T, class enable_if<is_base_of<Npc, T>::value>::type* = nullptr> class Builder{ private: T* instance; public: Npc::Builder<T>* create(); Npc::Builder<T>* name(string name); Npc::Builder<T>* charClass(string charClass); Npc::Builder<T>* hp(int hp); Npc::Builder<T>* mana(int mana); Npc::Builder<T>* attackPower(int attackPower); Npc::Builder<T>* magicPower(int magicPower); Npc::Builder<T>* defense(int defense); Npc::Builder<T>* magicDefense(int magicDefense); T* build(); }; }; Npc.cpp ... template<class T, class enable_if<is_base_of<Npc, T>::value>::type* = nullptr> Npc::Builder<T>* Npc::Builder<T>::create() { ... } main.cpp ... Npc::Builder<Warrior>* builder = new Npc::Builder<Warrior>(); ... Thanks!

Aucun commentaire:

Enregistrer un commentaire