Original Post
I need to do some serialization, and I'm wondering what the best route is (apart from using an already-existing library). Coming from Objective-C with a heavy runtime, serialization was a pretty easy job, but I'm wondering what the best design would be in C++. The elements that I need serialized are these: numbers (int or float), strings, arrays, dictionaries (key/value maps), booleans, and then hopefully objects. This question deals with handling the elements, not the actual serialization. I started by creating an abstract 'base' class from which each element would have a subclass with a member function returning an enumeration value to signify its type, but this also means I have to declare all accessor member functions as virtual in the base class, which isn't really nice, especially if other elements are added later. Then I found out about RTTI which would make life much easier. I could just do it using RTTI, but I've also read many comments from people basically saying that RTTI shouldn't ever be necessary and that you just need to design your classes better. So basically my question: Is there some nice way to design the class hierarchy with templates or whatever so that RTTI is indeed unnecessary? Anyone have experience writing something like this? Thanks.