"Copy of "with pointer

Started by
3 comments, last by raptorstrike 19 years, 3 months ago
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?
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Advertisement
It depends in part on how those templates are stored in the file.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
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?

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).
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
yeah thats what i was looking for thanks alot

[smile]

EDIT: yup that did it i implemented it without a hitch and its working great

[Edited by - raptorstrike on January 1, 2005 2:53:04 PM]
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie

This topic is closed to new replies.

Advertisement