Boost logo

Boost Users :

From: David Pettigrew (davidpett_at_[hidden])
Date: 2006-09-06 20:50:03


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 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