Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!ucsd!ucsdhub!hp-sdd!apollo!vinoski From: vinoski@apollo.HP.COM (Stephen Vinoski) Newsgroups: comp.lang.c++ Subject: Re: virt base c'tor -- my error or CC bug? Keywords: CC, cfront, 2.0, multiple inheritance, virtual base class Message-ID: <48359bd1.20b6d@apollo.HP.COM> Date: 23 Jan 90 16:46:00 GMT References: <11582@thorin.cs.unc.edu> Sender: root@apollo.HP.COM Reply-To: vinoski@zep.UUCP (Stephen Vinoski) Distribution: na Organization: Apollo Computer, Chelmsford, MA Lines: 38 In article <11582@thorin.cs.unc.edu> tuck@jason.cs.unc.edu (Russ Tuck) writes: >I think I've found a bug in the AT&T C++ 2.0 compiler, cfront, but I'm >willing to be shown the error in my code. On p. 82, section 12.6.2, of >the C++ (2.0) Reference Manual (AT&T select code 307-146), it says: >"All sub-objects for virtual base classes are initialized by the constructor >of the most derived class. If a constructor of the most derived class >does not specify a mem-initializer for a virtual base class then that >virtual base class must have a default constructor or no constructors." > >Here's a trivial example program showing this case. > > class V { public: V(int); }; > > class A : public virtual V { public: A(); }; > > A::A() : V(1) {} > > V v(1); > A a; From Lippman's "C++ Primer", Addison-Wesley, ISBN 0-201-16487-6, page 363: "A base class specified as virtual must, if it defines any constructors, define a constructor that does not require an argument list - either a constructor taking no arguments or one in which default value is provided for each argument." -steve P.S. IMHO Lippman's "C++ Primer" is the best C++ book going. If you don't have it you should get a copy. | Steve Vinoski | | Hewlett-Packard Apollo Division, Testability and Diagnostics Dept. | | Chelmsford, MA 01824 (508)256-6600 x5904 | | Internet: vinoski@apollo.com UUCP: {mit-eddie,yale,uw-beaver}!apollo!vinoski |