|
Boost Users : |
Subject: [Boost-users] [serialize] using virtual inheritance causes compiler error
From: Douwe Gelling (douwegelling_at_[hidden])
Date: 2016-10-26 11:45:05
Hi all,
When trying to serialize a class with a virtual base class, I'm getting
compilation errors. It seems to be part of a bug in type_traits, but I'm
wondering if anyone knows a workaround for making it work anyhow.
ultimately, the error boils down to "error: virtual function 'A::foo' has
more than one final overrider in 'boost_type_traits_internal_struct_X'",
using the code listing below..
It's simplified as much as possible, but obviously I need virtual
inheritance due to using diamond inheritance.
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/serialization.hpp>
struct A
{
virtual ~A(){};
virtual void foo() = 0;
template <class Archive>
void serialize(Archive& ar, const unsigned int version)
{
}
};
struct B : public virtual A
{
virtual void foo()
{
}
template <class Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar& boost::serialization::base_object<A>(*this);
}
};
struct C : public B
{
template <class Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar& boost::serialization::base_object<B>(*this);
}
};
BOOST_CLASS_EXPORT(C);
int main()
{
C c;
return 0;
}
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