C++ FAQ Celebrating Twenty-One Years of the C++ FAQ!!!
(Click here for a personal note from Marshall Cline.)
Section 36:
[36.12] Are there any caveats when serializing / unserializing objects?

One of the things you don't want to do, except in unusual circumstances, is to make any changes to the node's data during the traversal. For example, some people feel they can map from Node* to integer by simply adding an integer as a data member in the Node class. They also sometimes add a bool haveVisited flag as another data member within Node objects.

But this causes lots of multi-threading and/or performance problems. Your serialize() method can no longer be const, so even though it is logically just a reader of the node data, and even though it logically makes sense to have multiple threads reading the nodes at the same time, the actual algorithm writes into the nodes. If you fully understand threading and reader/writer conflicts, the best you can hope for is to make your code more complicated and slower (you'll have to block all reader threads whenever any thread is doing anything with the graph). If you (or those who will maintain the code after you!) don't fully understand reader/writer conflicts, this technique can create very serious and very subtle errors. Reader/writer and writer/writer conflicts are so subtle they often slip through test into the field. Bad news. Trust me. If you don't trust me, talk to someone you do trust. But don't cut corners.

There's lots more I could say, such as several simplifications and special cases, but I've already spent too much time on this. If you want more info, spend some money.