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: ka@socrates.hr.att.com (Kenneth Almquist) Subject: Re: Java vs Ada 95 (Was Re: Once again, Ada absent from DoD SBIR solicitation) Date: 1996/10/28 Message-ID: <5536en$2vk@nntpa.cb.lucent.com>#1/1 X-Deja-AN: 192915449 references: organization: Lucent Technologies, Columbus, Ohio newsgroups: comp.lang.ada Date: 1996-10-28T00:00:00+00:00 List-Id: mg@dsd.camb.inmet.com (Mitch Gart) wrote: > Calling superclass methods is easy in Java and hard in Ada: > > type parent_obj is tagged record ...; > type parent_ptr is access all parent_obj; > procedure p(param: access parent_obj); > > type child_obj is new parent_obj with ...; > type child_ptr is access all child_obj; > procedure p(param: access child_obj); > > now inside the child's p, to call the parent's p: > > p(parent_obj(param.all)'access); > > is the way to do it. Converting the pointer to parent_ptr won't work > because the call will dispatch back to the child. No it won't. Dispatching only occurs when you use class-wide types.[1] You don't explain why you are using access types. Normally you would write: type parent_obj is tagged record ...; procedure p(param: in out parent_obj); type child_obj is new parent_obj with ...; procedure p(param: in out child_obj); Now inside the child's p, to call the parent's p: p(parent_obj(param)); This reads quite well (or at least it would if parent_obj had a meaningful name). Kenneth Almquist [1] You don't want to convert to parent_ptr because of the possibility of accessibility errors. Instead use a pointer type declared in p: procedure p(param: access child_obj) is type super is access all parent_obj; begin ... p(super(param)); -- call the parent's p ... end p;