From: Ian Chapman Newsgroups: comp.os.msdos.djgpp Subject: Sword Date: Wed, 18 Dec 1996 12:29:15 -0500 Organization: Nortel Technology Lines: 110 Message-ID: <32B829EB.AB0@nortel.ca> NNTP-Posting-Host: bkanm382.bnr.ca Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Hi all, I originally sent this to Eric on the Sword program however he must have moved or be off for Christmas. Maybe another member of the sword project can help me. I've been looking over the SWORD project. I think that I've got it right. I've unzipped the sw21_v2, sw21_doc, and sw21_p2 files as I'm using djgpp 2.0. I've also printed the dot.ps file which has quite an interesting write-up. The first example is fail.cc. Since I'm new to c++ and the Sword authors are keen on understanding a point on this program I've tried it out. It failed to compile and I do not see why. I've concatenated a marked up version of fail.cc to this email. They also say that it gives the unexpected result TObject1 creation :: TObject1::foo TObject2 creation :: TObject1::foo The explanation given is TObject2 cannot call his virtual method foo during construction of its base object TObject1 because at this time virtual methods table for TObject2 does not exist yet. My explanation is more simple. When TObject2 is created it is derived from the base class TObject1 and the constructor for its base class is executed, TObject1::foo() is executed and TObject2::foo() is never called it looks dead code to me. So I have two question why compile errors and what is the point I'm missing. Je comprendre la Francaise pour lire et parle mais mon expression ecrite est mauvais comme vous pouvez voir. Bien a vous, Regards Ian. Voici fail.cc avec "compile errors" ajoute. Here is the code #include // --- class TObject1 definition class TObject1 { public: TObject1(); virtual void foo(); }; TObject1::TObject1() { foo(); } void TObject1::foo() { printf("TObject1::foo\n"); } // --- class TObject2 definition class TObject2 : public TObject1 { public: TObject2(); virtual void foo(); } TObject2::TObject2() : TObject1() { } //************* ERROR return type spec for constructor invalid. void TObject2::foo() { printf("TObject2::foo\n"); } void main(void) { TObject1 *O1; //*******Warning return type for main changed to integer type. TObject2 *O2; printf("TObject1 creation : "); O1=new TObject1(); printf("TObject2 creation : "); O2=new TObject2(); // delete O2; delete O1; }