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: 103376,7a180be12347b9d3 X-Google-Attributes: gid103376,public X-Google-Thread: 1108a1,7a180be12347b9d3 X-Google-Attributes: gid1108a1,public X-Google-ArrivalTime: 2002-02-12 00:30:36 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: dmitry@elros.cbb-automation.de (Dmitry A. Kazakov) Newsgroups: comp.lang.ada,comp.object Subject: Re: Merits of re-dispatching [LONG] Date: Tue, 12 Feb 2002 08:32:55 GMT Message-ID: <3c68ceeb.88774578@News.CIS.DFN.DE> References: <3c62524f.93369796@News.CIS.DFN.DE> <1013094178.985786@master.nyc.kbcfp.com> <3c6392e8.2400843@News.CIS.DFN.DE> <1013192956.289787@master.nyc.kbcfp.com> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) X-Trace: fu-berlin.de 1013502633 48191504 212.79.194.111 (16 [77047]) X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:19908 comp.object:34175 Date: 2002-02-12T08:32:55+00:00 List-Id: On Fri, 8 Feb 2002 13:30:04 -0500, "Hyman Rosen" wrote: >"Dmitry A. Kazakov" wrote in message news:3c6392e8.2400843@News.CIS.DFN.DE... >> First C++ does not make any difference between class wide and specific >> objects. The same type B is a class wide in B::f () and specific in >> B::~B (). So the difference in how B::f and B::~B are dealing with >> calls to g(). This is IMO bad. > >This is an incorrect view of what is happening. The type is class-wide >in both B::f and B::~B. Calls to B::g are dispatching in both. It's just >that while B::~B is running, the actual type of the object is B, so any >dispatching happens according to B's virtual functions, even if the B >part happened to be part of a derived class. That is one of several possible interpretation of what happens in C++ using Ada terms. However, I prefer mine, because it is consistent with the fact that the type tag [= vtab] is constant, thus the actual specific type is also constant. Like in Ada it is only a view conversion. >struct A { virtual void foo() { cout << "A::foo\n"; }void call_foo() { foo(); } virtual ~A() { call_foo(); } }; >struct B : A { void foo() { cout << "B::foo\n"; } ~B() { call_foo(); } } >struct C : B { void foo() { cout << "C::foo\n"; } ~C() { call_foo(); } }; > >When a C object is destructed, it will print "C::foo"., "B::foo", "A::foo". > >> type is already *known*. Thus there is no need in [re-]dispatching. A >> call to g() can be statically resolved. > >As in my example, not if the object is passed to some other routine which >makes the dispatching call. When you pass it to some other routine an implicit specific->class wide conversion happens, so the routine can dispatch again. An Ada 95 equivalent would be: procedure Y (A : in out Object'Class); procedure X (A : in out Object) is begin Y (A'Class (A)); end X; Exactly this behaviour is IMO unsafe. Regards, Dmitry Kazakov