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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8d0f3c1e28d13ede,start X-Google-Attributes: gid103376,public From: Gregory Lampshire Subject: Ada95 OOP programming: calling correct superclass procedure Date: 1996/11/25 Message-ID: <3299F04C.E86@mrj.com>#1/1 X-Deja-AN: 200686865 content-type: text/plain; charset=us-ascii organization: MRJ mime-version: 1.0 reply-to: gbol@mrj.com newsgroups: comp.lang.ada x-mailer: Mozilla 3.01Gold (Win95; I) Date: 1996-11-25T00:00:00+00:00 List-Id: I am having difficulty getting the right procedure to be called during a dispatching operation: 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; package body My_Objs is procedure Init (This : access A_Rec; I : Integer) is begin Do_Something_A_Specific (I); end; function Create_A return A is This : A := new A_Rec; begin Init (This); return This; end; procedure Init (This : access B_Rec; I : Integer) is begin * Init (This, I); Do_Something_B_Specific (I); end; function Create_B return B is This : B := new B_Rec; begin Init (This); return This; end; end; The "*" indicates where I have a problem. If I do the following; declare Me : B := Create_B; begin ... end; I get stuck in an endless loop (of course) because Init is dispatching. Note that both defs are in the same package so I cannot prefix the call with the package name. Also, I want the user only to see the Create definition, not the Init but I had to stick into the package to force it to be a primitive operation (for some definitions I do not mind exposing Init). I've tried casting using A'(This) but, of course, the tag does the correct dispatching anyway. How do I cast or resolve this problem within the constraints above? (same package, same calling args except 1st parameter, same procedure name, reference argument controlling formal parameter) I can always change the Init name to Init_A and Init_B but I was wondering how to do this in Ada95. It would be nice to have something like Parent.Init (This) where Parent is already defined as A in the above case. Perhaps I have an an OOP conceptual problem.