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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,adae40bcc4d01baf X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Ada 95 constructors on limited types Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <08dc2b30-6c8c-4cff-9f2e-c0d4c377972d@i3g2000hsf.googlegroups.com> Date: Wed, 2 Jan 2008 15:49:22 +0100 Message-ID: NNTP-Posting-Date: 02 Jan 2008 15:49:25 CET NNTP-Posting-Host: 57324048.newsspool4.arcor-online.net X-Trace: DXC=U>>UTGWC9bEFJ3]dH>I?oE4IUK On Wed, 2 Jan 2008 06:31:39 -0800 (PST), shaunpatterson@gmail.com wrote: > I am trying to write a constructor that will return an access type to > a new object. > > What I what is something like: > > procedure Test is > > Test_Pointer : Parent.Class_Access := new Parent.Child.Create (5); Test_Pointer := Parent.Child.Create (5); > begin > null; > end Test; > > Parent.ads: > > package Parent is > > type Class is abstract tagged limited null record; > type Class_Access is access all Class'Class; I would not use "access all" unless you need some instances of Class allocated on the stack. But that's aside. > end Parent; > > package Parent.Child is > > type Class is new Parent.Class with private; > > function Create (Test_Value : Integer) return Class_Access; > -- function Create (Test_Value : Integer) return Class; > > private > type Class is new Parent.Class with > record > Value : Integer := 0; > end record; > > end Parent.Child; > > package body Parent.Child is > > function Create (Test_Value : Integer) return Class_Access is > begin > return new Class' (Value => Test_Value); > -- Works only with Ada 2005... I am stuck using Ada 95 Result : Class_Access := new Class; -- Allocation This : Class renames Class (Result.all); -- Downcasting begin This.Value := Test_Value; -- Initialization return Result; > end Create; > > end Parent.Child; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de