comp.lang.ada
 help / color / mirror / Atom feed
From: Serge Robyns <serge.robyns@gmail.com>
Subject: Re: Declaring constants for a abstract tagged type and concrete sub classes
Date: Mon, 6 Jul 2015 06:49:35 -0700 (PDT)
Date: 2015-07-06T06:49:35-07:00	[thread overview]
Message-ID: <28d2406c-d579-4710-9b34-108317fe9abf@googlegroups.com> (raw)
In-Reply-To: <mndq80$h9m$1@dont-email.me>

On Monday, 6 July 2015 13:55:02 UTC+2, G.B.  wrote:
> On 06.07.15 12:10, Serge Robyns wrote:
> > package Abstract_Root is
> >     type T_Root is abstract tagged with private;
> >     procedure Set_XYZ (Self: in out T_Root; ABC : in Integer);
> >     function Get_XYZ (Self: in T_Root) return Integer;
> > private
> >     type T_Root is abstract tagged record
> >        XYZ : Integer;
> >     end record;
> > end Abstract_Root;
> 
> In case you can afford a publicly abstract but
> privately non-abstract type,
> 
> package Abstract_Root is
>     type T_Root is abstract tagged  private;
>     procedure Set_XYZ (Self: in out T_Root; ABC : in Integer);
>     function Get_XYZ (Self: in T_Root) return Integer;
>     No_Element : constant T_Root;  -- or T_Root'Class;
> private
>     type T_Root is tagged record
>        XYZ : Integer;
>     end record;
>     No_Element : constant T_Root := T_Root'(Xyz => 666);
> end Abstract_Root;
> 
> Every object needs to be of a concrete type, whether constant
> or not.
> 
> If what is wanted is some information about any object
> in T_Root'Class (its derivation hierarchy), such as
> being a "special" object acting as "no object", say,
> a function (to override) might do.

Seems not to work as expected, at least not on GNAT 2015.

If I use No_Element : constant T_Root; => I get "type of object cannot be abstract" compile error, which is what I used to have.  I thought your solution was to address a freezing rule issue.

When I use 'Class I get "type of aggregation cannot by class-wide" compile error.

Currently, I'm using an access pointer and use null to validate the result of searches.  It works fine, but I'm having for example Ada Containers that merely contains a access pointer to the an allocated object.  And the whole pointer mess I would love to avoid.  This is how I used to work in my C-days, while I've chosen Ada for my project for a set of reasons such as readability, reliability and it's track record in mission critical systems.

  reply	other threads:[~2015-07-06 13:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-06 10:10 Declaring constants for a abstract tagged type and concrete sub classes Serge Robyns
2015-07-06 11:55 ` G.B.
2015-07-06 13:49   ` Serge Robyns [this message]
2015-07-06 17:36     ` G.B.
2015-07-07 16:27       ` Serge Robyns
2015-07-07 17:21         ` G.B.
2015-07-07 19:51           ` Serge Robyns
2015-07-07 20:14             ` Simon Wright
2015-07-07 20:18             ` Jeffrey R. Carter
2015-07-06 15:42 ` Simon Wright
2015-07-06 16:35   ` Serge Robyns
2015-07-06 17:02     ` Bob Duff
2015-07-06 21:16       ` Serge Robyns
2015-07-06 17:30 ` gautier_niouzes
replies disabled

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