From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Dispatching problem.
Date: Tue, 15 Jan 2008 20:49:33 +0100
Date: 2008-01-15T20:49:33+01:00 [thread overview]
Message-ID: <9pcdfsa9h79f$.1naub13ik8tbd$.dlg@40tude.net> (raw)
In-Reply-To: 2d63ad45-4d52-4cb2-8dea-e1f92ecaacac@q77g2000hsh.googlegroups.com
On Tue, 15 Jan 2008 10:55:46 -0800 (PST), petter_fryklund@hotmail.com
wrote:
> I get compilation error when I try to dispatch a call using class
> wide access variables stating that I cannot call abstract program.
>
> Perhaps oversimplified example is:
>
> package PBN is
> type Item_T is abstract tagged null record;
> type Item_Ptr is access all Item_T'Class;
> function Create (From : in String) return access Item_T'Class is
> abstract;
> function Img (From : access Item_T'Class) return String is
> abstract;
This is a class-wide operation. As such it is not primitive (and does not
dispatch). For non-primitive operations declaring abstract means
disallowing in Ada.
[ My guess, you wanted:
function Img (From : access Item_T) return String is abstract;
(better: function Img (From : Item_T) return String is abstract;)
BTW, same applies to Create. It is a factory, so it should be
function Create (From : in String)
return access Item_T is abstract;
(better: function Create (From : in String) return Item_T;) ]
> end PBN;
>
> package PBN.Site is
> type Site_T is new Item_T with
> record
> Name : ASU.Unbounded_String;
> end record;
> type Site_Ptr is access all Site_T;
>
> function Create (From : in String) return Site_Ptr;
> function Img (From : access Site_T) return String;
This is an "overloading" for the disallowed operation above.
> end PBN.Site;
>
> with Ada.Text_IO;
> with PBN;
> with PBN.Site;
> procedure Print is
> Site : PBN.Item_Ptr;
> begin
> Site := PBN.Site.Create ("[Site qwerty]");
> Ada.Text_IO.Put_Line (Site.Img); <-----------------
> cannot call abstract program
This calls to the disallowed Img from PBN, the compiler tells you so.
> end Print;
>
> Any suggestions (apart from taking extensive course in OOD ;-) ?
Use new keywords of Ada 2005 indicating a desire to override, since you are
using that (damned (:-)) prefix notation anyway...
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2008-01-15 19:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-15 18:55 Dispatching problem petter_fryklund
2008-01-15 19:49 ` Dmitry A. Kazakov [this message]
2008-01-15 20:01 ` petter_fryklund
-- strict thread matches above, loose matches on Subject: below --
2003-02-06 14:04 Petter Fryklund
2003-02-06 15:33 ` James S. Rogers
2003-02-07 7:35 ` Petter Fryklund
2003-02-07 9:01 ` Dmitry A. Kazakov
2003-02-07 14:55 ` Petter Fryklund
2003-02-10 9:12 ` Dmitry A. Kazakov
2003-02-11 8:31 ` Petter Fryklund
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox