[serialization][limitation]

Hello again I've discovered one more problem. Commented code bellow doesn't compile, because of private inheritance. I don't think that it is a bug, but just limitation of the current implementation. But it limits use of C++, so, if I want to use boost::serialization library I don't allowed to use private inheritance. I don't think that it is very good :) Anyway, if it can not be fixed easily, this limitation should be explicitly stated in docs, or in library's code, that compiler error points to. Best, Oleg Abrosimov #include <boost/archive/text_iarchive.hpp> #include <boost/archive/text_oarchive.hpp> #include <boost/serialization/base_object.hpp> #include <boost/serialization/utility.hpp> #include <boost/serialization/list.hpp> #include <list> //class my_list1 : // private std::list<int> //{ // friend class boost::serialization::access; // template<class Archive> // void serialize(Archive &ar, const unsigned int version) // { // save/load base class information // ar & boost::serialization::base_object< std::list<int>
(*this); // } //}; // //void save(my_list1 const& lst, const char* const filename) //{ // std::ofstream ofs(filename); // boost::archive::text_oarchive oa(ofs); // oa << lst; //}
class my_list2 : public std::list<int> { friend class boost::serialization::access; template<class Archive> void serialize(Archive &ar, const unsigned int version) { // save/load base class information ar & boost::serialization::base_object< std::list<int>
(*this); } };
void save(my_list2 const& lst, const char* const filename) { std::ofstream ofs(filename); boost::archive::text_oarchive oa(ofs); oa << lst; } class my_list3 { std::list<int> m_lst; friend class boost::serialization::access; template<class Archive> void serialize(Archive &ar, const unsigned int version) { ar & m_lst; } }; void save(my_list3 const& lst, const char* const filename) { std::ofstream ofs(filename); boost::archive::text_oarchive oa(ofs); oa << lst; }
participants (1)
-
Oleg Abrosimov