tags:

views:

148

answers:

4

Im trying to text serialize and deserialize an object containing a container of abstract objects in c++,does somebody know of a code example of the above?

+1  A: 

You could create a method for your abstract class called:

virtual void serialize(char *out, int outLen) = 0;

.. and in turn a static deserializer:

AbstractClass deserialize(char *serializedString, int strLen);

In your deserializer, you could have different strategies to deserialize the right subclass of the abstract class.

cwap
+3  A: 

Take a look at boost::serialize.

It contains methods to assist in the serialization of containers (link loses frame on left).

Of course, don't just skip to that page, you'll want to read the whole thing. :)

GMan
+2  A: 

Unlike other languages, C++ doesn't come with this kind of serialization "baked in." You're going to want to use a library. Such as Boost.Serialization, Google Protocol Buffers (can be a file format) or Apache Thrift.

Max Lybbert
+1  A: 

Hey I asked a similar question a little while back. Have a look at dribeas's answer it was particularly good. This method allows the addition of new objects of the abstract type will little manipulation of existing code (ie. we can serialize them without adding additional switch/else if options to our deserializer).

http://stackoverflow.com/questions/1080448/best-practice-for-list-of-polymorphic-objects-in-c/1081064#1081064

DeusAduro
thanks guys....