From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada 95 constructors on limited types
Date: Wed, 2 Jan 2008 15:49:22 +0100
Date: 2008-01-02T15:49:25+01:00 [thread overview]
Message-ID: <vhfhc1j9u6si$.1pybv0qtevn1p$.dlg@40tude.net> (raw)
In-Reply-To: 08dc2b30-6c8c-4cff-9f2e-c0d4c377972d@i3g2000hsf.googlegroups.com
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
next prev parent reply other threads:[~2008-01-02 14:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-02 14:31 Ada 95 constructors on limited types shaunpatterson
2008-01-02 14:49 ` Dmitry A. Kazakov [this message]
2008-01-02 16:02 ` Robert A Duff
2008-01-02 16:20 ` Jeffrey R. Carter
2008-01-02 22:57 ` Brian May
2008-01-02 23:53 ` Jeffrey R. Carter
2008-01-05 10:32 ` Ludovic Brenta
2008-01-05 14:59 ` Robert A Duff
2008-01-08 1:58 ` Randy Brukardt
2008-01-02 18:36 ` Martin Krischik
2008-01-04 1:38 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox