From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.67.21.205 with SMTP id hm13mr54824380pad.16.1436190575604; Mon, 06 Jul 2015 06:49:35 -0700 (PDT) X-Received: by 10.140.36.170 with SMTP id p39mr526058qgp.28.1436190575559; Mon, 06 Jul 2015 06:49:35 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!qs7no894542igc.0!news-out.google.com!4ni66449qgh.1!nntp.google.com!w90no958914qge.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 6 Jul 2015 06:49:35 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=94.107.233.114; posting-account=6m7axgkAAADBKh082FfZLdYsJ24CXYi5 NNTP-Posting-Host: 94.107.233.114 References: <0ade6abf-34c0-46e2-8bd9-d60a00056321@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <28d2406c-d579-4710-9b34-108317fe9abf@googlegroups.com> Subject: Re: Declaring constants for a abstract tagged type and concrete sub classes From: Serge Robyns Injection-Date: Mon, 06 Jul 2015 13:49:35 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:26635 Date: 2015-07-06T06:49:35-07:00 List-Id: 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; >=20 > In case you can afford a publicly abstract but > privately non-abstract type, >=20 > 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 :=3D T_Root'(Xyz =3D> 666); > end Abstract_Root; >=20 > Every object needs to be of a concrete type, whether constant > or not. >=20 > 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; =3D> I get "type of object cannot be= abstract" compile error, which is what I used to have. I thought your sol= ution 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 whol= e pointer mess I would love to avoid. This is how I used to work in my C-d= ays, while I've chosen Ada for my project for a set of reasons such as read= ability, reliability and it's track record in mission critical systems.