Sorry, apparently this does work as-is.

I was confused about another error message I was getting from the compiler and it mistakenly lead me to believe it was not accessing the private constructor. Sorry for the mix up.

On Thu, Apr 2, 2009 at 7:11 PM, Robert Dailey <rcdailey@gmail.com> wrote:
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.