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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,bb06c19745c6aacb X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Use of abstract tagged types without access types -- again and complete Date: Thu, 09 Jun 2011 22:19:19 +0200 Organization: A noiseless patient Spider Message-ID: <87hb7yn4fs.fsf@ludovic-brenta.org> References: <53347692-e182-4f2f-8598-453af64e16fc@w36g2000vbi.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="FDxPUM0CiXePLGU2CCb79w"; logging-data="5868"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195F2zSjUzOvkX786vPEHZT" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:YoLShTGJo297PuHwojRpb+zJWfQ= sha1:CZeHaVftX/pBNFNgkYkVCnIHmaQ= Xref: g2news2.google.com comp.lang.ada:20691 Date: 2011-06-09T22:19:19+02:00 List-Id: "Prof. Dr. Carl Weierstrass" writes on comp.lang.ada: > type Parent_Type is new Ada.Finalization.Controlled with record > Child : Child_Type'Class; > end record; > > This doesn't work, because: > class-wide subtype with unknown discriminants in component declaration > > Of course I could use an access type to avoid the error but is there a > way to do something like this without access types. No. The reason is that the size of Child is unknown, so you cannot encapsulate a Child into a Parent_Type, which has a fixed size. In contrast, the size of an access value is fixed at comile time, so you can encapsulate an access value in the Parent_Type. What is it exactly that you want to achieve? Why do you think you need a record of a specific type to contain a record of a class-wide type? The reason I ask is because the usefulness of Parent_Type escapes me, since you can simply pass objects of type Child_Type'Class to subprograms so they dispatch dynamically. Also, why do you want to avoid access values in this case? Would you be happy with a reference-counted smart pointer instead? -- Ludovic Brenta.