From: petter_fryklund on
Hi all!

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;
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;
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
end Print;

Any suggestions (apart from taking extensive course in OOD ;-) ?

Regards,
Petter
From: Dmitry A. Kazakov on
On Tue, 15 Jan 2008 10:55:46 -0800 (PST), petter_fryklund(a)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
From: petter_fryklund on
On 15 Jan, 20:49, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de>
wrote:
> On Tue, 15 Jan 2008 10:55:46 -0800 (PST), petter_frykl...(a)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. Kazakovhttp://www.dmitry-kazakov.de

Thanks!