comp.lang.ada
 help / color / mirror / Atom feed
* Ada 95 constructors on limited types
@ 2008-01-02 14:31 shaunpatterson
  2008-01-02 14:49 ` Dmitry A. Kazakov
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: shaunpatterson @ 2008-01-02 14:31 UTC (permalink / 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








^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-01-08  1:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-02 14:31 Ada 95 constructors on limited types shaunpatterson
2008-01-02 14:49 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox