It's always the most derived class that is responsible for initializing all direct and indirect virtual bases. In other words, you have to do this:
Code:
class X {
public:
X() { }
X( int xx ) : x( xx ) { }
int getx() const { return x; }
private:
int x;
};
class Y : virtual public X {
public:
Y( int xx ) : X( xx ) { }
};
class Z : public Y {
public:
Z( int xx ) : X(xx), Y( xx ) { }
};
int main()
{
Z zobj( 100 );
cout << zobj.getx() << endl;
Note that both Z and Y have the call to the X constructor in their initializer list. This is because if a Z object is created, the Z version is used, whereas when an Y object is created, the Y version is used.
Are you sure virtual inheritance is what you want? You don't need it just for virtual functions. Virtual inheritance is something for multiple inheritance with common bases, and IMO the most confusing part of C++, more confusing even than template metaprogramming.