Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialize] using virtual inheritance causes compiler error
From: Robert Ramey (ramey_at_[hidden])
Date: 2016-10-26 21:22:19


On 10/26/16 8:45 AM, Douwe Gelling wrote:
> 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;
> }
>

Just some quick observations:

a) there is a example/test for diamond inheritance in the test suite
b) I don't see diamond inhertance in your example.
c) I might be helpful to indicate the compiler
d) Your not actually doing an serialization so I doubt you need "export"

I would keep cutting down the example until it starts to compile. I'm
very doubtful that this has anything to do with serialization or diamond
inheritance

Robert Ramey


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