Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!rochester!kodak!sisd!news From: jdg@sisd.kodak.com (Jeff Gortatowsky CUST) Newsgroups: comp.lang.c++ Subject: Fairly simple Multiple Inheritance Question Message-ID: <1990Jul25.121614.16958@sisd.kodak.com> Date: 25 Jul 90 12:16:14 GMT Sender: news@sisd.kodak.com Distribution: na Organization: Eastman Kodak Company, Rochester NY Lines: 36 Like many others I'm just getting started using g++ and TC++. Here's the question in code (shortened quite a bit). class A { ....... }; class B { ...... }; // C inherits A and B class C : public A, public B { .... }; // Note: has class B // D inherits only A class D : public A { ..... }; // Note: no class B // E should have everthing. 2 copies of A?? Better fix that virtually! class E : public C, public D { .... }; main () { E myObject(); // Construct a class E object B *ptrToB; // Pointer to class B object ptrToB = &myObject; // Illegal???? TC++ say it is. ptrToB = (B *) &myObject; // legal???? } Is the first assignment legal? One of the base classes of class E is class C which did inherit a class B object. However the other class inherited by class E was class D which did not inherit a class B object. Is that why the first assignment is wrong? The second works, it even runs right. I just want to know why if there is a base class object of type B in an object of class E I can't use a base class pointer without a cast. Please excuse any obvious stupidity on my part, I'm just starting to make the shift. -- Jeff Gortatowsky-Eastman Kodak Company .....uunet!atexnet!kodak!elmgate!jdg (716)-726-0084 Eastman Kodak makes film not comments. Therefore these comments are mine not theirs.