What is the best source, print or online, for learning how to implement persistence in C++? I want to save my objects to disk and restore them, and I want to learn how to do this from scratch, not by purchasing someone’s library.
I don’t know which compiler you are using. If you are using Visual C++ and MFC, then you are pretty much be forced into using their model of object persistence. Al Stevens had a book, C++ Database Development, that covered this to some degree, but that’s an older book. I don’t know of any book that focuses just on this topic but I’m sure you could find a discussion in any good C++ book.
The basic concept is pretty straightforward: The object knows best what needs to be saved to disk. So you can write a Serialize method for your classes. Then, you can basically tell an object to save itself. Perhaps the hardest part is determining which object must be created and told to load itself when reading a file. For this, you need to also save information about that object to the file.