"Copy of "with pointer
ok i have a set of monsters that i make in a source file and these will be the template of all my monsters then i want to make copies of those templates and use them in the actual game. How would i achive this?
its just an instance of the class for example
Monster* MMonster = new Monster("Monster Stats/Monster.txt",Skills);
i never want to tuch this data after its declared just make copies of it
Monster* MMonster = new Monster("Monster Stats/Monster.txt",Skills);
i never want to tuch this data after its declared just make copies of it
Right, I understood that much, but what does your data look like in the file? Or do you already have code to load that data and you're just looking at how to implement a Clone() function?
You then just have to implement your copy constructor correctly (if at all necessary).
struct Clonable{ virtual ~Clonable() {} virtual Clonable* Clone() const = 0;};class Monster : public Clonable{public: // If your compiler supports covariant return types Monster* Clone() const { return new Monster(*this); } // Otherwise Clonable* Clone() const { return new Monster(*this); }};
You then just have to implement your copy constructor correctly (if at all necessary).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement