comp.lang.ada
 help / color / mirror / Atom feed
From: "Marc A. Criley" <mcNOSPAM@mckae.com>
Subject: Dispatching confusion
Date: Sun, 18 Jul 2010 08:25:36 -0500
Date: 2010-07-18T08:25:36-05:00	[thread overview]
Message-ID: <a31c6$4c430064$433a4efa$4498@API-DIGITAL.COM> (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



             reply	other threads:[~2010-07-18 13:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-18 13:25 Marc A. Criley [this message]
2010-07-18 13:40 ` Dispatching confusion Robert A Duff
2010-07-18 15:06   ` Marc A. Criley
replies disabled

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