From: Gregory Lampshire <gbol@mrj.com>
Subject: Ada95 OOP programming: calling correct superclass procedure
Date: 1996/11/25
Date: 1996-11-25T00:00:00+00:00 [thread overview]
Message-ID: <3299F04C.E86@mrj.com> (raw)
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.
next reply other threads:[~1996-11-25 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-11-25 0:00 Gregory Lampshire [this message]
1996-11-27 0:00 ` Ada95 OOP programming: calling correct superclass procedure Jon S Anthony
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox