Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!rochester!kodak!ispd-newsserver!tuna!randolph From: randolph@ssd.kodak.com (Gary L. Randolph) Newsgroups: comp.lang.c++ Subject: Direct derivation of virtual base Message-ID: <1990Nov19.211251.13416@ssd.kodak.com> Date: 19 Nov 90 21:12:51 GMT Sender: news@ssd.kodak.com Distribution: usa Organization: Eastman Kodak Lines: 66 Originator: randolph@tuna The following hierarchy is set up by code found below: X priv/|\priv Y | Z \|/ XYZ Note that the derivations of Y and Z are private. BUT the virtual base is derived *publicly* by XYZ. Therefore, I would expect XYZ to inherit public members directly through this path. Please do NOT tell me about the fact that pointer conversion from derived to base is not allowed due to the private derivation, I know that and am not expecting conversion. I have two questions: 1.) Why is X a private base class to XYZ even though I publicly derive it for XYZ? 2.) In general, what is gained from deriving a virtual base class directly? Assuming all derivations above were public, what would an XYZ get that it wouldn't have from Y and Z anyway? The following code results in the compile time error: "tst.C", line 31: error: main() cannot access f : X is a private base class WHY???????? #include class X{ public: virtual void f(); }; class Y : virtual private X{ }; class Z : virtual private X{ }; class XYZ : public Y, public Z, virtual public X{ }; void X::f() { cout<<"\nX::f() "; } int main(){ XYZ * xyzp = new XYZ; xyzp->f(); //LINE 31 } Gary Randolph randolph@ssd.kodak.com