comp.lang.ada
 help / color / mirror / Atom feed
From: jsa@alexandria (Jon S Anthony)
Subject: Re: Ada95 OOP programming: calling correct superclass procedure
Date: 1996/11/27
Date: 1996-11-27T00:00:00+00:00	[thread overview]
Message-ID: <JSA.96Nov26202616@alexandria> (raw)
In-Reply-To: 3299F04C.E86@mrj.com


In article <3299F04C.E86@mrj.com> Gregory Lampshire <gbol@mrj.com> 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





      reply	other threads:[~1996-11-27  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-25  0:00 Ada95 OOP programming: calling correct superclass procedure Gregory Lampshire
1996-11-27  0:00 ` Jon S Anthony [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox