I have written code to serialize a class hierarchy (with lots of
shared_ptrs, strings, vectors etc.). This compiles (and works) on gcc 4.1.2
(OpenSuse 10.3).
When trying to compile it on an older machine (gcc 3.3.3) I am getting lots
of compiler errors which seem to boil down to the issue the the
(de)serialization code fails to instantiate some abstract class in the
hierarchy.
I understand that instantiating these classes has to fail, what I do not
understand is why the same code compiles with gcc 4.1.2...
any ideas?
What I did was:
I have defined the following typedefs/macros
typedef boost::archive::binary_iarchive InArchive;
typedef boost::archive::binary_oarchive OutArchive;
#define DECLARE_AS_SERIALIZABLE \
friend class boost::serialization::access; \
void serialize(InArchive & ar, const unsigned int file_version); \
void serialize(OutArchive & ar, const unsigned int file_version)
and have augmented each and every class in the hierarchy with the line
DECLARE_AS_SERIALIZABLE /* inside the class */
BOOST_SERIALIZATION_SHARED_PTR(Node); /* after the class decl. */
in the .cpp file I have
BOOST_CLASS_EXPORT_GUID(mepl::Node, "Node") // for each class
and the implementation of the serialize methods
void Node::serialize(InArchive & ar, const unsigned int /* file_version */){
ar & BOOST_SERIALIZATION_NVP(m_sFileName)
//& BOOST_SERIALIZATION_NVP(m_sSource)
// & BOOST_SERIALIZATION_NVP(m_parentNode)
& BOOST_SERIALIZATION_NVP(m_iStartLine)
& BOOST_SERIALIZATION_NVP(m_iStartColumn)
& BOOST_SERIALIZATION_NVP(m_iEndLine)
& BOOST_SERIALIZATION_NVP(m_iEndColumn);
}
void ExprNode::serialize(InArchive & ar, const unsigned int /* file_version
*/){
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Node);
bool bConst;
ar & BOOST_SERIALIZATION_NVP(m_type)
& BOOST_SERIALIZATION_NVP(bConst)
& BOOST_SERIALIZATION_NVP(m_wert);
m_bIsConst=bConst;
}
etc.
As I've said, this works beautifully with gcc 4.1.2.
Have I made a mistake here? Or is the older compiler not suppored in by
Boost.Serialization?
Small part of the compiler's output
//melos/prog/boost/include/boost-1_34_1/boost/serialization/access.hpp: In
static member function `static void
boost::serialization::access::construct(Archive&, T*) [with Archive =
boost::archive::binary_iarchive, T = mepl::Node]':
//melos/prog/boost/include/boost-1_34_1/boost/serialization/serialization.hpp:105:
instantiated from `void boost::serialization::load_construct_data(Archive&,
T*, unsigned int) [with Archive = boost::archive::binary_iarchive, T =
mepl::Node]'
//melos/prog/boost/include/boost-1_34_1/boost/serialization/serialization.hpp:170:
instantiated from `void
boost::serialization::load_construct_data_adl(Archive&, T*, unsigned int)
[with Archive = boost::archive::binary_iarchive, T = mepl::Node]'
//melos/prog/boost/include/boost-1_34_1/boost/archive/detail/iserializer.hpp:308:
instantiated from `void boost::archive::detail::pointer_iserializer