Boost logo

Boost Users :

From: Jan Eickmann (je_at_[hidden])
Date: 2005-04-17 07:29:23


Hi,

I'm trying to serialize a list of shared_ptr's to objects.

Here's a summary of the code I have:

namespace MyNamespace
{

class B
{
//implementation plus standard serialization function
};

class A
{
private:
        list< shared_ptr<B> > myBs;
public:
        template<class Archive>
        void serialize(Archive & ar, const unsigned int version)
        {
                ar & BOOST_SERIALIZATION_NVP(myBs);
        }
};

}

If I just try to serialize it, I get an unregistered_class exception. So
I think I have to use BOOST_SHARED_POINTER_EXPORT(_GUID) to register the
shared_ptr.

When I include this inside the namespace (please note that the error
messages are from my real code, so they have slightly other names:

BOOST_SHARED_POINTER_EXPORT(B)

I get this:
  f:\xenocide\xenocide\src\common\simulation\simulation.h(108) : error
C2059: syntax error : 'string'
f:\xenocide\xenocide\src\common\simulation\simulation.h(108) : error
C2146: syntax error : missing ';' before identifier
'BOOST_CLASS_EXPORT_GUID'
f:\xenocide\xenocide\src\common\simulation\simulation.h(108) : error
C2059: syntax error : 'string'
f:\xenocide\xenocide\src\common\simulation\simulation.h(109) : error
C2143: syntax error : missing ';' before '}'

When I put it outside the namespace I have to use a fully qualified name
including the namespace for class B, so it becomes

BOOST_SHARED_POINTER_EXPORT(MyNamespace::B)

Then I get (not Xenocide is here what MyNamespace is in my example):
f:\xenocide\xenocide\src\common\simulation\simulation.h(115) : error
C2653: '__shared_ptr_Xenocide' : is not a class or namespace name
f:\xenocide\xenocide\src\common\simulation\simulation.h(115) : error
C2653: '__shared_ptr_Xenocide' : is not a class or namespace name

I also tried various combinations with BOOST_SHARED_POINTER_EXPORT_GUID
but it didn't help.

Can someone explain to me how I have to declare shared_ptr's in order
for them to work with boost::serialization? I was unable to find some
more indepth documentation.

Thanks,

Jan Eickmann


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net