$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Robert Ramey (ramey_at_[hidden])
Date: 2006-09-07 11:56:53
its seems that 'GUIWidget has a private constructor.  When serialization 
tries to construct a MyClass instance while loading a pointer, things would 
fail. In order to fix this you either have to make GUIWidget::GUIWidget 
public or protected or use override load_construct to replace the default 
construction with one that uses the factory that creates GUIWidget.
Robert Ramey
"David Pettigrew" <davidpett_at_[hidden]> wrote in message 
news:36bb165a0609061750k4882b23el124327a6a567c961_at_mail.gmail.com...
I have a class that is derived from a GUI framework class and it seems like 
the serialization library will attempt to serialize the parent class but I 
don't own that classes code. I get an error "'GUIWidget::GUIWidget' : cannot 
access private member declared in class 'GUIWidget'". I do not know why it 
is looking in the parent class since I do not do anything with the 
base_object. Is there a way to get around this issue? I am doing somethine 
wrong?
Here is the code,
#include <boost/archive/tmpdir.hpp>
#include <boost/archive/text_wiarchive.hpp>
#include <boost/archive/text_woarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <fstream>
#include <iostream>
namespace boost
{
    namespace serialization
    {
        class access;
    }
}
class MyClass: public GUIWidget
{
public:
    MyClass();
    ~MyClass();
private:
    std::vector<LSLogEntry> m_logEntryList; // LSLogEntry has wstring 
members.
    friend class boost::serialization::access;
    // When the class Archive corresponds to an output archive, the
    // & operator is defined similar to <<.  Likewise, when the class 
Archive
    // is a type of input archive the & operator is defined similar to >>.
    template<class Archive>
    void serialize(Archive & ar, const unsigned int version)
    {
        ar & m_logEntryList;
    }
};
// free functions
void save(const MyClass& eftw, const char * filename)
{
    std::string fullPath(boost::archive::tmpdir());
    fullPath += filename;
    // save the schedule
    try
    {
        // make an archive
        std::wofstream ofs(fullPath.c_str());
        boost::archive::text_woarchive oa(ofs);
        oa << eftw;
    } catch (boost::archive::archive_exception e)
    {
        wcout << e.what();
    }
}
void load(MyClass& eftw, const char * filename)
{
    std::string fullPath(boost::archive::tmpdir());
    fullPath += filename;
    // Restore the data
    try
    {
        // open the archive
        std::wifstream ifs(fullPath.c_str());
        boost::archive::text_wiarchive ia(ifs);
        // restore from the archive
        ia >> eftw;
    } catch (boost::archive::archive_exception e)
    {
        wcout << e.what();
    }
}
Thanks,
David
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://listarchives.boost.org/mailman/listinfo.cgi/boost-users