From: Marc A. Criley on 18 Jul 2010 09:25 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
From: Robert A Duff on 18 Jul 2010 09:40 "Marc A. Criley" <mcNOSPAM(a)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
From: Marc A. Criley on 18 Jul 2010 11:06 On 07/18/2010 08:40 AM, Robert A Duff wrote: > "Marc A. Criley"<mcNOSPAM(a)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
|
Pages: 1 Prev: Ada.Directories and network shares Next: Determining value of record discriminant |