Jump to content
  • Advertisement
Sign in to follow this  
Adams555

Save a class to file, and later load it.

This topic is 5061 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

Hello. I am working on a 'very' small mmorpg, and have gotten to the point where multiple users can enter the game. I've decided I need to make an account system now, and I thought the best way to do that is to have a player class (already done) and save that to a file from time to time, and at logout. This class will probably be changing quite a bit, so it would be best if I didn't have to change the saving code every time i want to add more variables, if possible. Anyway, is there any way to save a class to a file, and load it later, without having to put each individual part in the files? Thanks. ~Adams555~

Share this post


Link to post
Share on other sites
Advertisement
Maybe you could have a struct within the class which has all the variables which should be saved (remember, no pointers in the struct) and then just write the struct to the file.

Share this post


Link to post
Share on other sites
Try using google with the word C++ Serialize. This is basically what you want to do: serialize the object to some persisent store. This may give you some ideas on how to do it.

Chris

Share this post


Link to post
Share on other sites
What you want is called _Serialization_. Theres a good tutorial about the subject and implentation of it in the Enginuity series part V (right here on gamedev.net)
http://www.gamedev.net/reference/programming/features/enginuity5/

You should also check out the realy new addition to the boost library: Serialization library
http://www.boost.org/libs/serialization/doc/index.html

I also wrote (before the boosts serialization lib came out) a xml serializer, which works a bit like the boosts.
http://koti.mbnet.fi/kumikana/soodaus/cpp/CXml/xml%20parser.zip

Id go with the boosts serialization library or atleast give it try.

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!