|
Boost Users : |
Subject: [Boost-users] [serialization] Private default constructors
From: Robert Dailey (rcdailey_at_[hidden])
Date: 2009-04-02 20:11:11
I have a class that can be constructed statically in code, or constructed by
data (this is where boost::serialization comes in).
For example:
class foo
{
public:
foo() {}
foo( std::string text )
: m_text( text )
{}
private:
template< class Archive >
void serialize( Archive& archive, unsigned int version )
{
archive & m_text;
}
std::string m_text;
friend class boost::serialization::access;
};
There is one problem with this, though. It is possible for a user of this
class to create a "foo" with the default constructor, thus enabling them to
have "zombie" objects. The only thing I want using the default constructor
is boost::serialization, not the user. Is there a way I can make the default
constructor private and still have boost::serialization access it? Keep in
mind that this must work polymorphically too.
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