Jump to content
  • Advertisement
Sign in to follow this  
raptorstrike

"Copy of "with pointer

This topic is 4979 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!