comp.lang.ada
 help / color / mirror / Atom feed
From: "Michael Garrett" <michaelgarrett@csi.com>
Subject: Run Time Dispatch Question
Date: 2000/02/25
Date: 2000-02-25T11:47:26+00:00	[thread overview]
Message-ID: <895q4e$5up$1@ssauraaa-i-1.production.compuserve.com> (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







             reply	other threads:[~2000-02-25  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-02-25  0:00 Michael Garrett [this message]
2000-02-25  0:00 ` Run Time Dispatch Question John English
2000-02-26  0:00   ` Michael Garrett
replies disabled

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