Virtual inheritance and constructors
So I have three classes:
Code:
class Base {
int i;
public:
Base(int value) : i(value) {}
};
class Derived : virtual public Base {
public:
Derived(int value) : Base(value) {}
};
class VeryDerived : public Derived {
VeryDerived(int value) : Derived(value) {}
};
I think I misunderstand how virtual inheritance and c++ constructors interact. This all seems to be reasonable, but my compiler tells me that VeryDerived cannot compile because there's no default Base constructor. None of the articles I've found online seem to mention this issue. Can anybody clarify my misunderstanding?
EDIT: by the way, I understand that in this limited example there's no need for virtual inheritance, but I am boiling down an issue that I'm having with something that I intend to be multiply-inherited. In my real program, I want to both make a non-multiply-inherited subclass of Derived and a multiply-inherited subclass of Derived.
Re: Virtual inheritance and constructors
Re: Virtual inheritance and constructors
With virtual inheritance, the most-derived class is responsible for constructing the virtual bases. Since you didn't explicitly call the Base(int) ctor, it's trying to find a Base(void) ctor, and none exists.