From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: How to?: Re-dispatching within an inherited method
Date: 1999/08/09
Date: 1999-08-09T00:00:00+00:00 [thread overview]
Message-ID: <7onk8f$2qg@hobbes.crc.com> (raw)
In-Reply-To: 37AF0ADE.3D80FEB3@hiwaay.net
Anthony E. Glover wrote in message <37AF0ADE.3D80FEB3@hiwaay.net>...
>Is it possible to re-dispatch a method call within an inherited method?
>For example:
>
>package A defines a type widget that has methods widget_size and
run_widget.
>package B defines a type bigwidget that has an overriding method for
>widget_size, but
>inherits the run_widget method without modification.
>Within package A, run_widget makes a call to widget_size. Is it
>possbile to force
>a re-dispatch such that the appropriate widget_size method gets called
based
>on the object passed into run_widget?
>
Yes. You need to type convert the actual parameter in the call to
Widget'Class to make the call a dispatching call. See RM 95 3.9.2 (1, 5).
As in the example:
with Ada.Text_IO;
package body A is
procedure Run_Widget (The_Widget : Widget'Class) is
begin
Ada.Text_IO.Put_Line
("in Run_Widget (The_Widget : Widget): Size =" &
Positive'Image (Widget_Size (Widget'Class (The_Widget))));
end Run_Widget;
function Widget_Size (The_Widget : Widget) return Positive is
begin
return 1;
end Widget_Size;
end A;
package A is
type Widget is tagged null record;
procedure Run_Widget (The_Widget : Widget'Class);
function Widget_Size (The_Widget : Widget) return Positive;
end A;
package body B is
function Widget_Size (The_Widget : BigWidget) return Positive is
begin
return 10;
end Widget_Size;
end B;
with A;
package B is
type BigWidget is new A.Widget with null record;
function Widget_Size (The_Widget : BigWidget) return Positive;
end B;
with A;
with B;
procedure Glover is
The_Widget : A.Widget;
The_BigWidget : B.BigWidget;
begin
A.Run_Widget (The_Widget);
A.Run_Widget (The_BigWidget);
end Glover;
next prev parent reply other threads:[~1999-08-09 0:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-08-09 0:00 How to?: Re-dispatching within an inherited method Anthony E. Glover
1999-08-09 0:00 ` David C. Hoos, Sr. [this message]
1999-08-17 0:00 ` Matthew Heaney
1999-08-17 0:00 ` David C. Hoos, Sr.
1999-08-18 0:00 ` Matthew Heaney
1999-08-18 0:00 ` Anthony E. Glover
1999-08-19 0:00 ` Matthew Heaney
1999-08-21 0:00 ` Anthony E. Glover
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox