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,8d0f3c1e28d13ede X-Google-Attributes: gid103376,public From: jsa@alexandria (Jon S Anthony) Subject: Re: Ada95 OOP programming: calling correct superclass procedure Date: 1996/11/27 Message-ID: #1/1 X-Deja-AN: 201050412 sender: news@organon.com (news) references: <3299F04C.E86@mrj.com> organization: Organon Motives, Inc. newsgroups: comp.lang.ada Date: 1996-11-27T00:00:00+00:00 List-Id: In article <3299F04C.E86@mrj.com> Gregory Lampshire writes: > package My_Objs is > type A_Rec is tagged private; > type A is access all A_Rec'Class; > procedure Init (This : access A_Rec; I : Integer); > function Create_A return A; > > type B_Rec is new A_Rec with private; > type B is access all B_Rec'Class; > procedure Init (This : access B_Rec; I : Integer); > function Create_B return B; > end; ... > procedure Init (This : access B_Rec; I : Integer) is > begin > * Init (This, I); > Do_Something_B_Specific (I); > end; ... > The "*" indicates where I have a problem. If I do the following; ... > I get stuck in an endless loop (of course) because Init is Because you are call B's init inside B's init. On the "*" line you pass This to Init. This is of type access to B_Rec. Not surprisingly, Init(access B_Rec,...) gets called again. Change this to: Init(A(This), I) > I've tried casting using A'(This) but, of course, the tag > does the correct dispatching anyway. Ooops! Drop the "'" /Jon -- Jon Anthony Organon Motives, Inc. Belmont, MA 02178 617.484.3383 jsa@organon.com