0

Is there an easy way to write a class that contains other classes and arrays of pointers to other classes to a file? Thanks!

BramKel
  • 63
  • 2
  • 7

1 Answers1

0

What you want to look into is called serialisation. It's the method of turning an object into a stream of bytes. The opposite is called deserialisation and is for constructing an object from a stream of bytes.

There is no way to do this automatically in vanilla C++, and if you would just write the object to file just like that from the object's address and size you would not write all that it points to.

Serialisation can be done in a lot of ways, either manually or using a third party library. I personally really like the Cereal library for serialisation/deserialisation in C++. Link here

Tobias
  • 924
  • 9
  • 23
  • Thanks for the fast reply! One quick question, do you know if it's possible to do serialisation in Qt? With the build-in features – BramKel Jun 09 '15 at 22:44
  • @BramKel Not sure, haven't used it myself but this seems promising depending on what you need: http://stackoverflow.com/questions/2570679/serialization-with-qt – Tobias Jun 09 '15 at 22:46