Boost logo

Boost Users :

From: Sergey Skorniakov (s.skorniakov_at_[hidden])
Date: 2005-01-11 08:06:09


Hello, All!

This code:

#include <fstream>
#include <boost/archive/polymorphic_text_iarchive.hpp>
#include <boost/archive/polymorphic_text_oarchive.hpp>
#include <boost/archive/polymorphic_binary_iarchive.hpp>
#include <boost/archive/polymorphic_binary_oarchive.hpp>
#include <boost/serialization/binary_object.hpp>

int main(int argc, char* argv[])
{
    {
        char testdata[4] = "asd";
        std::ofstream os("test.txt", std::ios::binary);
        boost::archive::polymorphic_binary_oarchive ar(os);
// boost::archive::polymorphic_text_oarchive ar(os);
// boost::archive::text_oarchive ar(os);
// boost::archive::binary_oarchive ar(os);
        ar & boost::serialization::make_binary_object(&testdata,
sizeof(testdata));
        assert(os.good());
    }
    {
        char testdata[4] = " ";
        std::ifstream is("test.txt", std::ios::binary);
        assert(is.good());
        boost::archive::polymorphic_binary_iarchive ar(is);
// boost::archive::polymorphic_text_iarchive ar(is);
// boost::archive::text_iarchive ar(is);
// boost::archive::binary_iarchive ar(is);
        ar & boost::serialization::make_binary_object(&testdata,
sizeof(testdata));
        assert(is.good());
        assert(testdata[0] == 'a');
    }
    return 0;
}

does not work as expected - last assert failed. With
text_iarchive/text_oarchive or binary_iarchive/binary_oarchive everything
works fine. With polymorphic_text_archive another assert failed - is.good()
returns false. I'm using VC 7.1 compiler. I had trying to compile this code
with Intel 8.1 compiler but got errors, identical for polymorphic binary and
text archives :

Compiling with Intel(R) C++ 8.1 ...(Intel C++ Environment)
TestPolyArchives.cpp
C:\boost_1_32_0\boost/serialization/binary_object.hpp(43): error #308:
function "boost::archive::polymorphic_oarchive::save_binary" is inaccessible
ar.save_binary(m_t, m_size);
^
detected during:
instantiation of "void boost::serialization::binary_object::save(Archive &,
const unsigned int) const [with
Archive=boost::archive::polymorphic_oarchive]" at line 90 of
"C:\boost_1_32_0\boost/serialization/access.hpp"
instantiation of "void boost::serialization::access::member_save(Archive &,
const T &, const unsigned int) [with
Archive=boost::archive::polymorphic_oarchive,
T=boost::serialization::binary_object]" at line 42 of
"C:\boost_1_32_0\boost/serialization/split_member.hpp"
instantiation of "void boost::serialization::detail::member_saver<Archive,
T>::invoke(Archive &, const T &, const unsigned int) [with
Archive=boost::archive::polymorphic_oarchive,
T=boost::serialization::binary_object]" at line 63 of
"C:\boost_1_32_0\boost/serialization/split_member.hpp"
instantiation of "void boost::serialization::split_member(Archive &, T &,
const unsigned int) [with Archive=boost::archive::polymorphic_oarchive,
T=boost::serialization::binary_object]" at line 49
instantiation of "void
boost::serialization::binary_object::serialize(Archive &, const unsigned
int) [with Archive=boost::archive::polymorphic_oarchive]" at line 106 of
"C:\boost_1_32_0\boost/serialization/access.hpp"
[ 4 instantiation contexts not shown ]
instantiation of "void
boost::archive::detail::save_non_pointer_type<Archive, T>::invoke(Archive &,
const T &) [with Archive=boost::archive::polymorphic_oarchive,
T=boost::serialization::binary_object]" at line 551 of
"C:\boost_1_32_0\boost/archive/detail/oserializer.hpp"
instantiation of "void boost::archive::save(Archive &, const T &) [with
Archive=boost::archive::polymorphic_oarchive,
T=boost::serialization::binary_object]" at line 106 of
"C:\boost_1_32_0\boost/archive/polymorphic_oarchive.hpp"
instantiation of "void
boost::archive::polymorphic_oarchive::save_override(const T &, int) [with
T=boost::serialization::binary_object]" at line 87 of
"C:\boost_1_32_0\boost/archive/detail/interface_oarchive.hpp"
instantiation of "Archive
&boost::archive::detail::interface_oarchive<Archive>::operator&(const T &)
[with Archive=boost::archive::polymorphic_oarchive,
T=boost::serialization::binary_object]" at line 159 of
"C:\boost_1_32_0\boost/archive/detail/polymorphic_oarchive_impl.hpp"
instantiation of "boost::archive::polymorphic_oarchive
&boost::archive::detail::polymorphic_oarchive_impl<ArchiveImplementation>::operator&(const
T &) [with
ArchiveImplementation=boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive>,
T=boost::serialization::binary_object]"
C:\boost_1_32_0\boost/serialization/binary_object.hpp(47): error #308:
function "boost::archive::polymorphic_iarchive::load_binary" is inaccessible
ar.load_binary(const_cast<void *>(m_t), m_size);
^
detected during:
instantiation of "void boost::serialization::binary_object::load(Archive &,
const unsigned int) [with Archive=boost::archive::polymorphic_iarchive]" at
line 98 of "C:\boost_1_32_0\boost/serialization/access.hpp"
instantiation of "void boost::serialization::access::member_load(Archive &,
T &, const unsigned int) [with Archive=boost::archive::polymorphic_iarchive,
T=boost::serialization::binary_object]" at line 53 of
"C:\boost_1_32_0\boost/serialization/split_member.hpp"
instantiation of "void boost::serialization::detail::member_loader<Archive,
T>::invoke(Archive &, T &, const unsigned int) [with
Archive=boost::archive::polymorphic_iarchive,
T=boost::serialization::binary_object]" at line 63 of
"C:\boost_1_32_0\boost/serialization/split_member.hpp"
instantiation of "void boost::serialization::split_member(Archive &, T &,
const unsigned int) [with Archive=boost::archive::polymorphic_iarchive,
T=boost::serialization::binary_object]" at line 49
instantiation of "void
boost::serialization::binary_object::serialize(Archive &, const unsigned
int) [with Archive=boost::archive::polymorphic_iarchive]" at line 106 of
"C:\boost_1_32_0\boost/serialization/access.hpp"
[ 5 instantiation contexts not shown ]
instantiation of "void boost::archive::load(Archive &, T &) [with
Archive=boost::archive::polymorphic_iarchive,
T=boost::serialization::binary_object]" at line 107 of
"C:\boost_1_32_0\boost/archive/polymorphic_iarchive.hpp"
instantiation of "void boost::archive::polymorphic_iarchive::load_override(T
&, int) [with T=boost::serialization::binary_object]" at line 105 of
"C:\boost_1_32_0\boost/archive/detail/interface_iarchive.hpp"
instantiation of "Archive
&boost::archive::detail::interface_iarchive<Archive>::operator>>(const T &)
[with Archive=boost::archive::polymorphic_iarchive,
T=boost::serialization::binary_object]" at line 111 of
"C:\boost_1_32_0\boost/archive/detail/interface_iarchive.hpp"
instantiation of "Archive
&boost::archive::detail::interface_iarchive<Archive>::operator&(const T &)
[with Archive=boost::archive::polymorphic_iarchive,
T=boost::serialization::binary_object]" at line 182 of
"C:\boost_1_32_0\boost/archive/detail/polymorphic_iarchive_impl.hpp"
instantiation of "boost::archive::polymorphic_iarchive
&boost::archive::detail::polymorphic_iarchive_impl<ArchiveImplementation>::operator&(const
T &) [with
ArchiveImplementation=boost::archive::binary_iarchive_impl<boost::archive::binary_iarchive>,
T=boost::serialization::binary_object]"
compilation aborted for .\TestPolyArchives.cpp (code 2)

With best regards, Sergey.


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