* Dispatching and Child Packages
@ 2001-03-21 0:12 Klatt, Nathan
2001-03-21 6:53 ` Simon Wright
2001-03-21 9:20 ` Peter Hend�n
0 siblings, 2 replies; 3+ messages in thread
From: Klatt, Nathan @ 2001-03-21 0:12 UTC (permalink / raw)
Is it possible to dispatch from within a child package? The below code does
not work. If I collapse the child packages into their respective parents,
it dispatches as expected. (Ndk is an empty package.)
Thanks,
Nathan Klatt
----------------------------------------------------------------------------
package Ndk.Base is
type Base is abstract tagged null record;
end Ndk.Base;
----------------------------------------------------------------------------
package Ndk.Base.Child is
procedure Do_Something (This : Base'Class);
procedure Real_Do_Something (This : Base) is abstract;
end Ndk.Base.Child;
----------------------------------------------------------------------------
package body Ndk.Base.Child is
procedure Do_Something (This : Base'Class) is
begin
Real_Do_Something (This);
end Do_Something;
end Ndk.Base.Child;
----------------------------------------------------------------------------
with Ndk.Base;
package Ndk.Sub is
type Sub is new
Ndk.Base.Base with null record;
end Ndk.Sub;
----------------------------------------------------------------------------
package Ndk.Sub.Child is
procedure Real_Do_Something (This : Sub);
end Ndk.Sub.Child;
----------------------------------------------------------------------------
with Ada.Text_Io;
package body Ndk.Sub.Child is
procedure Real_Do_Something (This : Sub) is
begin
Ada.Text_Io.Put_Line ("Sub doing something...");
end Real_To_String;
end Ndk.Sub.Child;
----------------------------------------------------------------------------
Compiler error:
Real_Do_Something (This); is a call on an abstract subprogram which should
be a dispatching call [RM_95 3.9.3(7)]
RM_95 3.9.3(7) says...
A call on an abstract subprogram shall be a dispatching call;
nondispatching calls to an abstract subprogram are not allowed.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Dispatching and Child Packages
2001-03-21 0:12 Dispatching and Child Packages Klatt, Nathan
@ 2001-03-21 6:53 ` Simon Wright
2001-03-21 9:20 ` Peter Hend�n
1 sibling, 0 replies; 3+ messages in thread
From: Simon Wright @ 2001-03-21 6:53 UTC (permalink / raw)
"Klatt, Nathan" <nklatt@excite.com> writes:
> Is it possible to dispatch from within a child package? The below code does
> not work. If I collapse the child packages into their respective parents,
> it dispatches as expected. (Ndk is an empty package.)
So why didn't you include it :-)
> ----------------------------------------------------------------------------
> package Ndk.Base is
>
> type Base is abstract tagged null record;
>
> end Ndk.Base;
> ----------------------------------------------------------------------------
> package Ndk.Base.Child is
>
> procedure Do_Something (This : Base'Class);
> procedure Real_Do_Something (This : Base) is abstract;
>
> end Ndk.Base.Child;
> ----------------------------------------------------------------------------
> package body Ndk.Base.Child is
>
> procedure Do_Something (This : Base'Class) is
> begin
> Real_Do_Something (This);
> end Do_Something;
GNAT says:
ndk-base-child.adb:6:09: cannot call abstract subprogram "Real_Do_Something"
ndk-base-child.adb:6:28: class-wide argument not allowed here
ndk-base-child.adb:6:28: "Real_Do_Something" is not a primitive operation of "Base"
and the last remark is your problem. You need to declare
Real_Do_Something in Ndk.Base.
> package body Ndk.Sub.Child is
>
> procedure Real_Do_Something (This : Sub) is
> begin
> Ada.Text_Io.Put_Line ("Sub doing something...");
> end Real_To_String;
^^^^^^^^^ ahem! I don't think you compiled this before
posting!
> end Ndk.Sub.Child;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Dispatching and Child Packages
2001-03-21 0:12 Dispatching and Child Packages Klatt, Nathan
2001-03-21 6:53 ` Simon Wright
@ 2001-03-21 9:20 ` Peter Hend�n
1 sibling, 0 replies; 3+ messages in thread
From: Peter Hend�n @ 2001-03-21 9:20 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 471 bytes --]
"Klatt, Nathan" wrote:
> Is it possible to dispatch from within a child package? The below code
does
> not work. If I collapse the child packages into their respective parents,
> it dispatches as expected. (Ndk is an empty package.)
No, dispatching operations must be declared in the package where the type is
declared.
Regards,
Peter
--
Peter Hend�n http://www.algonet.se/~phenden
ICQ: 14672398
Teknisk Dokumentation AB http://www.tdab.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-03-21 9:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-21 0:12 Dispatching and Child Packages Klatt, Nathan
2001-03-21 6:53 ` Simon Wright
2001-03-21 9:20 ` Peter Hend�n
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox