comp.lang.ada
 help / color / mirror / Atom feed
* Run Time Dispatch Question
@ 2000-02-25  0:00 Michael Garrett
  2000-02-25  0:00 ` John English
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Garrett @ 2000-02-25  0:00 UTC (permalink / raw)



I am back to my study of Ada...

I am having a problem understanding run time dispatching. ( Basic question I
know, but I'm having a brain cramp. )


I have declared a basic type using a class wide access variable link to the
next object.
When I create a simple linked list and a class wide access variable to point
into the list,
I get a compile time error when calling procedure p( .... ), a dispatching
procedure.
( which works for compile time dispatching ).


What is my problem???


with ada.text_io;
use ada.text_io;

procedure main7 is
-------------------------------------------------------
    type t;
    type pt is access all t'class;

    type t is tagged record
        next : pt := null;
    end record;
 -------------------------------------------------------
    type t1 is new t with record
        x : integer;
    end record;

    procedure p( this : t1 ) is
    begin
        put_line(" in p(t1)");
    end p;
-------------------------------------------------------
    type t2 is new t1 with record
        y : integer;
    end record;

    procedure p( this : t2 ) is
    begin
        put_line("in p(t2)");
    end p;
-------------------------------------------------------
begin
    -- static dispatching, compile time
    put_line("Compile Time Dispatching");
    declare
        tt1 : t1;
        tt2 : t2;
    begin
        tt1.x := 10;
        tt2.x := 5;
        tt2.y := 40;
        p(tt1);
        p(tt2);
    end;
    -- end compile time dispatching

    put_line("Run Time Dispatching");
    declare
        ptrt : pt;
        it : pt;        -- classwide access type
    begin
        ptrt := new t1;
        ptrt.next := new t2;
        it := ptrt.next; -- it references a t2 object, second in list.
        p(it.all);    -- PROBLEM
    end;

end main7;




--
Thank You!!
Michael C. Garrett







^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-02-26  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-25  0:00 Run Time Dispatch Question Michael Garrett
2000-02-25  0:00 ` John English
2000-02-26  0:00   ` Michael Garrett

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