From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1108a1,7a180be12347b9d3 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,7a180be12347b9d3 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-02-07 17:24:53 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada,comp.object Subject: Re: Merits of re-dispatching [LONG] Date: Thu, 7 Feb 2002 20:29:42 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: <3c62524f.93369796@News.CIS.DFN.DE> <1013094178.985786@master.nyc.kbcfp.com> X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 X-Complaints-To: newsabuse@supernews.com Xref: archiver1.google.com comp.lang.ada:19748 comp.object:33618 Date: 2002-02-07T20:29:42-05:00 List-Id: "Hyman Rosen" wrote in message news:1013094178.985786@master.nyc.kbcfp.com... > Again, this is false for C++. In a C++ constructor or destructor, the > type of the object is the type of the class of which the constructor or > destructor is a member. So in the C++ equivalent of Finalize(A), the > call to Foo(A'Class) would call Foo(A), not Foo(AA), because in > the destructor of A, the object is an A, not an AA, even when we > are destructing the A component of an AA. This is good, since, as > you point out, the AA part is no longer there! Yes, that's true, but it's easy to think that the virtual member function call will dispatch, because that's how it works for every other virtual member function: class B { public: virtual ~B(); virtual void f(); virtual void g(); }; void B::f() { g(); //dispatches } B::~B() { g(); //does not dispatch } You have to learn that the call to g() doesn't dispatch in the dtor. This behavior is certainly not immediately obvious, especially for those new to the language. You seemed to have missed the point about this error-prone feature of C++: a naive programmer is going to depend on dispatching to occur. He has to learn --the hard way-- that the dtor is special. > True, but the error is that (from their point of view) the wrong function > gets called, not that the right function gets called on destructed pieces > of objects. But the point is that it is an error, that is very easy to make. > I guess this is another entry for my "why C++ is better than Ada" file :-) Again, you seemed to have missed the point. The scenario Dmitry described cannot happed by accident in Ada95: the programmer must have taken special action for it to occur. This is not the case in C++. (Note that I like C++, and I use it every day. But by any measure Ada95 is a much safer language than C++.)