comp.lang.ada
 help / color / mirror / Atom feed
From: adam@irvine.com (Adam Beneschan)
Subject: Ada 95 dispatching question
Date: 1997/11/26
Date: 1997-11-26T00:00:00+00:00	[thread overview]
Message-ID: <880581829.29833@dejanews.com> (raw)


What should the following program output?  I'm trying to get it to
output

    3/TRUE/"abcdefghij"/ 15

but it outputs instead

    3/TRUE/???

when compiled with GNAT 3.01.

If the output is correct, then why?  In particular, is the line marked
"<=== HERE" a dispatching call, and if not, why not?  And how would I
have to modify the program to get it to do what I'd like it to do,
given that declaring do_to_aux and do_to_rec in PACK1 is not an
option?

(My apologies if the problem is that I made a stupid mistake.)

                                -- thanks, Adam


package pack1 is

    type auxinfotype is tagged null record;

    type auxinfotype_p is access auxinfotype'class;

    type rectype is record
        f1 : integer;
        f2 : boolean;
        f3 : auxinfotype_p;
    end record;

end pack1;


with pack1;
package pack2 is

    type auxinfotype2 is new pack1.auxinfotype with null record;

    procedure do_to_aux (a : in auxinfotype2);

    procedure do_to_rec (r : in pack1.rectype);

end pack2;



with text_io;
package body pack2 is

    procedure do_to_aux (a : in auxinfotype2) is
    begin
        text_io.put ("???");
    end do_to_aux;

    procedure do_to_rec (r : in pack1.rectype) is
    begin
        text_io.put (integer'image (r.f1) & "/" & boolean'image (r.f2) &
                     "/");
        do_to_aux (auxinfotype2 (r.f3.all));       -- <=== HERE
        text_io.new_line;
    end do_to_rec;

end pack2;


with pack2;
package pack3 is

    type auxinfotype3 is new pack2.auxinfotype2 with record
        af1 : string (1 .. 10);
        af2 : integer;
    end record;

    procedure do_to_aux (a : in auxinfotype3);

end pack3;


with text_io;
package body pack3 is

    procedure do_to_aux (a : in auxinfotype3) is
    begin
        text_io.put ('"' & a.af1 & """/" & integer'image (a.af2));
    end do_to_aux;

end pack3;


with pack1;
with pack2;
with pack3;
procedure test is
    a : pack3.auxinfotype3;
    r : pack1.rectype;
begin
    a.af1 := "abcdefghij";
    a.af2 := 15;
    r.f1 := 3;
    r.f2 := true;
    r.f3 := new pack3.auxinfotype3' (a);
    pack2.do_to_rec (r);
end test;

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet




             reply	other threads:[~1997-11-26  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-11-26  0:00 Adam Beneschan [this message]
1997-11-26  0:00 ` Ada 95 dispatching question Matthew Heaney
1997-11-27  0:00 ` Olivier Hainque
1997-11-27  0:00   ` Olivier Hainque
replies disabled

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