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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3ccb707f4c91a5f2 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Invoking parental methods (was: Java vs Ada 95) Date: 1996/11/05 Message-ID: #1/1 X-Deja-AN: 194622739 sender: news@inmet.camb.inmet.com (USENET news) x-nntp-posting-host: houdini.camb.inmet.com references: organization: Intermetrics, Inc. newsgroups: comp.lang.ada Date: 1996-11-05T00:00:00+00:00 List-Id: Mitch Gart (mg@harp.camb.inmet.com) wrote: : Larry Kilgallen (kilgallen@eisner.decus.org) wrote: : : But the dangling reference seems to be precipitated by the : : the pointer object, not by the the pointer type. : : What is wrong with: : : type super is access all parent_obj; -- this line may get changed : : procedure p_first(param: access child_obj) is : : begin : : ... : : p_first(super(param)); -- call the parent's p_first : : ... : : end p_first; : This is the trap I fell into the first time I tried to write this code. : The above solution doesn't work because the type conversion super(param) : converts param into a pointer to the parent type, but tag inside the : object that is pointed to still says the object is a child_obj, not a : parent_obj, so the call dispatches to the wrong place. No, the call as written does not dispatch at all, because the actual parameter is of an access-to-specific, rather than an access-to-class-wide type. The above call is a statically bound call to the p_first of the parent type. *However* the above call does involve a conversion to a library-level named access type, "super", which results in a run-time accessibility check. The check will succeed unless the original caller passed in a pointer to a local aliased/heap object. The call which avoids the accessibility check, and accomplishes the statically bound call on the parent's operation, is: p_first(parent(param.all)'access); : ... This line : : p_first(super(param)); -- call the parent's p_first : in fact doesn't call the parent's p_first, in spite of the comment. If : the object pointed to by "param" is a child_obj this call is an infinite : resursion. No, that's not right. It does call the parent's p_first, but it also performs an accessibility check, which may not be desired. : - Mitch Gart -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Cambridge, MA USA