Assuming that Bar
should inherit from Foo
(which is not the case in the current example), the problem you see here is usually called a diamond . Which version of Foo
do you want to use, Bar::foo()
or Foo::foo()
? You will need to specify virtual inheritance:
struct Foo{ ~virtual Foo(){} void foo(){} }; struct Bar : virtual public Foo struct Baz : virtual public Foo, public Bar
so that he knows that there is only one type of foo()
. Therefore, virtual inheritance is used to call foo()
inside the constructor.
Edit:
And to be clear, I assume that you want Bar
inherit from Foo
. If you do not have this in the code, then this is the reason for the bad error. There is no inheritance hierarchy for Bar
to go to Foo
. In addition, modern compilers should not even compile without virtual inheritance, but some legacy compilers would gladly be @ # $ # $ it.
And if I'm going to comment on another answer, I'd rather follow my own answer!
wheaties
source share