comp.lang.ada
 help / color / mirror / Atom feed
From: shaunpatterson@gmail.com
Subject: Ada 95 constructors on limited types
Date: Wed, 2 Jan 2008 06:31:39 -0800 (PST)
Date: 2008-01-02T06:31:39-08:00	[thread overview]
Message-ID: <08dc2b30-6c8c-4cff-9f2e-c0d4c377972d@i3g2000hsf.googlegroups.com> (raw)

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);

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;

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
    end Create;

--  function Create (Test_Value : Integer) return Class is
--    begin
--       return Class' (Value => Test_Value);
--    end Create;

end Parent.Child;


So, the first create works in Ada2005 with:

  Test_Pointer : Parent.Class_Access := Parent.Child.Create (5);

I have also tried the second Create unsuccessfully with

  Test_Pointer : Parent.Class_Access := new Parent.Child.Create (5);


I don't understand how to initialize limited types and their pointers.

Any help?  Again, my project currently is tied down to Ada95 (gnat
3.16p)

--
Shaun








             reply	other threads:[~2008-01-02 14:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-02 14:31 shaunpatterson [this message]
2008-01-02 14:49 ` Ada 95 constructors on limited types Dmitry A. Kazakov
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