comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: Ada 95 dispatching question
Date: 1997/11/26
Date: 1997-11-26T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023680002611971952300001@news.ni.net> (raw)
In-Reply-To: 880581829.29833@dejanews.com


In article <880581829.29833@dejanews.com>, adam@irvine.com (Adam Beneschan)
wrote:


>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;

No, the marked line is NOT a dispatching call.  You downcasted the root
type to a specific type - not a classwide type - and so do_to_aux binds
statically, to the version for auxinfotype2.

The rule in Ada is, you only dispatch on an object whose type is T'Class. 
Had you downcasted to the classwide type auxinfotype2'Class, ie

do_to_aux (auxinfotype2'Class (r.f3.all));

then dispatching would occur.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




  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 Ada 95 dispatching question Adam Beneschan
1997-11-26  0:00 ` Matthew Heaney [this message]
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