Hello,

I am encountering the following  warning when using virtual base class pointer to serialize a derived class. The same warning is displayed for all sample test programs that come with the serialization library. The compiler used is g++ version 3.4.3.

 

 

/vob/adc/router/thirdparty/boost/boost/type_traits/is_virtual_base_of.hpp:56: warning: direct base `TestBase' inaccessible in `boost::detail::is_virtual_base_of_impl<TestBase, TestType1, mpl_::bool_< true> >::X' due to ambiguity

 

Can you recommend any workarounds…or if this has been addressed.

 

Thanks

Sulakshan V

 

 

#include <boost/archive/xml_oarchive.hpp>

#include <boost/archive/xml_iarchive.hpp>

#include <boost/serialization/nvp.hpp>

#include <boost/serialization/base_object.hpp>

#include <boost/serialization/type_info_implementation.hpp>

#include <boost/serialization/export.hpp>

#include <boost/serialization/extended_type_info_no_rtti.hpp>

#include <boost/archive/archive_exception.hpp>

#include <boost/archive/basic_xml_archive.hpp>

#include <fstream>

 

class TestBase

{

public:

        TestBase() : m_baseInt(111) {}

        virtual ~TestBase() {}

 

        virtual const char* get_key() const = 0;

 

private:

        friend class boost::serialization::access;

    template<class Archive>

    void serialize(Archive& ar, const unsigned int)

        {

                ar & boost::serialization::make_nvp("BaseInt", m_baseInt);

        }

 

        int m_baseInt;

};

 

BOOST_SERIALIZATION_ASSUME_ABSTRACT(TestBase)

BOOST_CLASS_TYPE_INFO(TestBase, extended_type_info_no_rtti<TestBase>)

BOOST_CLASS_EXPORT(TestBase)

 

class TestType1 : public TestBase

{

public:

        TestType1() : m_int(666), m_float(777.f) {}

 

        virtual const char* get_key() const;

 

private:

        friend class boost::serialization::access;

        template<class Archive>

        void serialize(Archive& ar, const unsigned int version)

        {

                ar & boost::serialization::make_nvp("TestBase", boost::serialization::base_object<TestBase>(*this));

                ar & boost::serialization::make_nvp("Type1Int", m_int);

                ar & boost::serialization::make_nvp("Type1Float", m_float);

        }

 

        int m_int;

        float m_float;

};

 

BOOST_CLASS_TYPE_INFO(TestType1, extended_type_info_no_rtti<TestType1>)

BOOST_CLASS_EXPORT(TestType1)

 

const char* TestType1::get_key() const

{

        return boost::serialization::type_info_implementation<TestType1>::type::get_const_instance().get_key();

}

 

class TestType2 : public TestBase

{

public:

        TestType2() : m_int(222), m_float(333.f) {}

 

        virtual const char* get_key() const;

 

private:

        friend class boost::serialization::access;

        template<class Archive>

        void serialize(Archive& ar, const unsigned int version)

        {

                ar & boost::serialization::make_nvp("TestBase", boost::serialization::base_object<TestBase>(*this));

                ar & boost::serialization::make_nvp("Type2Int", m_int);

                ar & boost::serialization::make_nvp("Type2Float", m_float);

        }

 

        int m_int;

        float m_float;

};

 

BOOST_CLASS_TYPE_INFO(TestType2, extended_type_info_no_rtti<TestType2>)

BOOST_CLASS_EXPORT(TestType2)

 

const char* TestType2::get_key() const

{

        return boost::serialization::type_info_implementation<TestType2>::type::get_const_instance().get_key();

}

 

int main(int argc, char** argv[])

{

        //Create new file

        std::ofstream testTypeOFS("TestType.xml");

        boost::archive::xml_oarchive testOutXML(testTypeOFS);

        TestType1* pT1 = new TestType1;

        TestType2* pT2 = new TestType2;

        testOutXML << boost::serialization::make_nvp("TestType1", pT1);

        testOutXML << boost::serialization::make_nvp("TestType2", pT2);

        testTypeOFS.close();

        delete pT1;

        delete pT2;

 

        //Load the file back in to extract a derived type.

        std::ifstream testTypeIFS("TestType.xml");

        boost::archive::xml_iarchive testInXML(testTypeIFS);

 

        TestBase* pTB = NULL;

        try

        {

                testInXML >> boost::serialization::make_nvp("TestBase", pTB);

        }

        catch(boost::archive::archive_exception& ex)

        {

                std::cout << "Archive Exception: " << ex.code << "-" << ex.what() << std::endl;

                char exitNotice;

                std::cin >> exitNotice;

        }

        testTypeIFS.close();

 

        return 0;

}

 

 

 

 

/vob/adc/router/thirdparty/boost/boost/type_traits/is_virtual_base_of.hpp:56: warning: direct base `TestBase' inaccessible in `boost::detail::is_virtual_base_of_impl<TestBase, TestType2, mpl_::bool_< true> >::X' due to ambiguity

/vob/adc/router/thirdparty/boost/boost/type_traits/is_virtual_base_of.hpp: In instantiation of `boost::detail::is_virtual_base_of_impl<TestBase, TestType1, mpl_::bool_< true> >::X':

/vob/adc/router/thirdparty/boost/boost/type_traits/is_virtual_base_of.hpp:70:   instantiated from `boost::detail::is_virtual_base_of_impl<TestBase, TestType1, mpl_::bool_< true> >'

/vob/adc/router/thirdparty/boost/boost/type_traits/is_virtual_base_of.hpp:78:   instantiated from `boost::detail::is_virtual_base_of_impl2<TestBase, TestType1>'

/vob/adc/router/thirdparty/boost/boost/type_traits/is_virtual_base_of.hpp:87:   instantiated from `boost::is_virtual_base_of<TestBase, TestType1>'

/vob/adc/router/thirdparty/boost/boost/mpl/if.hpp:67:   instantiated from `boost::mpl::if_<boost::is_virtual_base_of<TestBase, TestType1>, boost::mpl::identity<boost::serialization::void_cast_detail::void_caster_virtual_base<TestType1, TestBase> >, boost::mpl::identity<boost::serialization::void_cast_detail::void_caster_primitive<TestType1, TestBase> > >'

/vob/adc/router/thirdparty/boost/boost/mpl/eval_if.hpp:37:   instantiated from `boost::mpl::eval_if<boost::is_virtual_base_of<TestBase, TestType1>, boost::mpl::identity<boost::serialization::void_cast_detail::void_caster_virtual_base<TestType1, TestBase> >, boost::mpl::identity<boost::serialization::void_cast_detail::void_caster_primitive<TestType1, TestBase> > >'

/vob/adc/router/thirdparty/boost/boost/serialization/void_cast.hpp:271:   instantiated from `const boost::serialization::void_cast_detail::void_caster& boost::serialization::void_cast_register(const Derived*, const Base*) [with Derived = TestType1, Base = TestBase]'

/vob/adc/router/thirdparty/boost/boost/serialization/base_object.hpp:68:   instantiated from `static const void* boost::serialization::detail::base_register<Base, Derived>::polymorphic::invoke() [with Base = TestBase, Derived = TestType1]'

/vob/adc/router/thirdparty/boost/boost/serialization/base_object.hpp:82:   instantiated from `static const void* boost::serialization::detail::base_register<Base, Derived>::invoke() [with Base = TestBase, Derived = TestType1]'

/vob/adc/router/thirdparty/boost/boost/serialization/base_object.hpp:104:   instantiated from `typename boost::serialization::detail::base_cast<B, D>::type& boost::serialization::base_object(Derived&) [with Base = TestBase, Derived = TestType1]'

x.cpp:48:   instantiated from `void TestType1::serialize(Archive&, unsigned int) [with Archive = boost::archive::xml_iarchive]'

/vob/adc/router/thirdparty/boost/boost/serialization/access.hpp:118:   instantiated from `static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive, T = TestType1]'

/vob/adc/router/thirdparty/boost/boost/serialization/serialization.hpp:74:   instantiated from `void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive, T = TestType1]'

/vob/adc/router/thirdparty/boost/boost/serialization/serialization.hpp:133:   instantiated from `void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive, T = TestType1]'

/vob/adc/router/thirdparty/boost/boost/archive/detail/iserializer.hpp:182:   instantiated from `void boost::archive::detail::iserializer<Archive, T>::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::xml_iarchive, T = TestType1]'

x.cpp:93:   instantiated from here

/vob/adc/router/thirdparty/boost/boost/type_traits/is_virtual_base_of.hpp:56: warning: direct base `TestBase' inaccessible in `boost::detail::is_virtual_base_of_impl<TestBase, TestType1, mpl_::bool_< true> >::X' due to ambiguity