Hi All,

Having already developed fixed-type binary tree classes in the past, I am reasonably familiar with the process of serialization and the graph topology of tree structures in general. However, I am currently attempting to implement a generalized C++ tree template and have absolutely no idea as to which approach is best suited for serialization.

As the template may be qualified with both primitive and non-POD types, what is the best technique for generalising node serialization within the base template code?

Please note that this is an exercise in C++ class/template building and as such, the STL/C++ Library will not be used.

Any advice would be gratefully received.

Best regards, Gemma.

9 Years
Discussion Span
Last Post by LincolnGurl

In this case, only the client code knows how data can be serialized, so your best bet is to require the client to give you a serializer for the data (whose interface you provide). This also helps to make a clean break between the data, which is owned by the client, and the tree structure, which is owned by your class.

If you look at some of the libraries here, you'll see a similar genericity technique where the data-specific operations are detached and defined by the client to overcome the "I don't know what I can do with this" problem.


Absolutely brilliant; exact information presented in a precise manner!

You're officially my *HERO* of the week!

Thank you ever so much!!!


This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.