comp.lang.ada
 help / color / mirror / Atom feed
* Dispatching confusion
@ 2010-07-18 13:25 Marc A. Criley
  2010-07-18 13:40 ` Robert A Duff
  0 siblings, 1 reply; 3+ messages in thread
From: Marc A. Criley @ 2010-07-18 13:25 UTC (permalink / raw)


I'm by why this  bit of class-wide dispatching I'm trying to use isn't 
compiling. Granted, I haven't used it much over the years, but it seemed 
pretty straightforward. I've concocted a representative example that 
exhibits the problem, and so I would appreciate a pointer to what I'm 
missing here.

This example simple declares an abstract type, then then derives two 
child types from it. A Dispatcher procedure taking the class-wide form 
of the abstract type is declared that invokes a procedure defined for 
each of the two child types, the atual one being determined at run time, 
depending on the concrete type of the argument. However, GNAT GPL 2010 
(Ubuntu 10.04) refuses to compile this, citing an argument/parameter 
type mismatch. I'm sure it's right, but I don't understand why.

Marc A. Criley

-------------------------------------------------------------
package Wrack_Machinery is

    type Wrack_Base is abstract tagged null record;

    procedure Dispatcher(W : Wrack_Base'Class);

    type Wrack_Client_Base is new Wrack_Base with null record;

    procedure Crank(WC : Wrack_Client_Base);

    type Wrack_Pub_Base is new Wrack_Base with null record;

    procedure Crank (WP : Wrack_Pub_Base);

end Wrack_Machinery;

with Text_IO; use Text_IO;

package body Wrack_Machinery is

    procedure Dispatcher(W : Wrack_Base'Class) is
    begin
       Crank(W);
    end Dispatcher;

    procedure Crank(WC : Wrack_Client_Base) is
    begin
       Put_Line("Client Crank");
    end Crank;

    procedure Crank (WP : Wrack_Pub_Base) is
    begin
       Put_Line("Pub Crank");
    end Crank;


end Wrack_Machinery;

with Wrack_Machinery;

procedure Wrack_Main is

    Client : Wrack_Machinery.Wrack_Client_Base;
    Pub    : Wrack_Machinery.Wrack_Pub_Base;

begin
    Wrack_Machinery.Dispatcher(Client);
    Wrack_Machinery.Dispatcher(Pub);
end Wrack_Main;
-----------------------------------------------------
$ gnatmake wrack_main
gcc -c wrack_main.adb
gcc -c wrack_machinery.adb
wrack_machinery.adb:7:07: no candidate interpretations match the actuals:
wrack_machinery.adb:7:13: expected type "Wrack_Pub_Base" defined at 
wrack_machinery.ads:11
wrack_machinery.adb:7:13: found type "Wrack_Base'Class" defined at 
wrack_machinery.ads:3
wrack_machinery.adb:7:13:   ==> in call to "Crank" at wrack_machinery.ads:13
wrack_machinery.adb:7:13:   ==> in call to "Crank" at wrack_machinery.ads:9
gnatmake: "wrack_machinery.adb" compilation error



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

* Re: Dispatching confusion
  2010-07-18 13:25 Dispatching confusion Marc A. Criley
@ 2010-07-18 13:40 ` Robert A Duff
  2010-07-18 15:06   ` Marc A. Criley
  0 siblings, 1 reply; 3+ messages in thread
From: Robert A Duff @ 2010-07-18 13:40 UTC (permalink / raw)


"Marc A. Criley" <mcNOSPAM@mckae.com> writes:

> package Wrack_Machinery is
>
>    type Wrack_Base is abstract tagged null record;

You forgot this one:
    procedure Crank(WC : Wrack_Base) is abstract;

>    procedure Dispatcher(W : Wrack_Base'Class);
>
>    type Wrack_Client_Base is new Wrack_Base with null record;
>
>    procedure Crank(WC : Wrack_Client_Base);

It would be a good idea to say "overriding", here and below:
   overriding procedure Crank(WC : Wrack_Client_Base);

And to use the GNAT style switch that warns of missing
"overriding".

>    type Wrack_Pub_Base is new Wrack_Base with null record;
>
>    procedure Crank (WP : Wrack_Pub_Base);
>
> end Wrack_Machinery;

- Bob



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

* Re: Dispatching confusion
  2010-07-18 13:40 ` Robert A Duff
@ 2010-07-18 15:06   ` Marc A. Criley
  0 siblings, 0 replies; 3+ messages in thread
From: Marc A. Criley @ 2010-07-18 15:06 UTC (permalink / raw)


On 07/18/2010 08:40 AM, Robert A Duff wrote:
> "Marc A. Criley"<mcNOSPAM@mckae.com>  writes:
>
>> package Wrack_Machinery is
>>
>>     type Wrack_Base is abstract tagged null record;
>
> You forgot this one:
>      procedure Crank(WC : Wrack_Base) is abstract;

D'oh!!!

Thanks Bob, that broke the logjam.

Marc



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

end of thread, other threads:[~2010-07-18 15:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-18 13:25 Dispatching confusion Marc A. Criley
2010-07-18 13:40 ` Robert A Duff
2010-07-18 15:06   ` Marc A. Criley

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