comp.lang.ada
 help / color / mirror / Atom feed
From: Victor Porton <porton@narod.ru>
Subject: Re: A good program that not compile
Date: Wed, 21 May 2014 17:24:31 +0300
Date: 2014-05-21T17:24:31+03:00	[thread overview]
Message-ID: <llicus$mmh$1@speranza.aioe.org> (raw)
In-Reply-To: llic43$kge$1@speranza.aioe.org

Now it works! 100%

No need to change Ada standard.

The latest listing follows:

-- my.ads
with Ada.Finalization;

package My is

   type Abstract_Handle is abstract new Ada.Finalization.Limited_Controlled with
      record
         Handle: Integer;
      end record;

   function Obtain_Handle(Object: Abstract_Handle) return Integer is abstract;

   overriding procedure Initialize(Object: in out Abstract_Handle);

   type File_Handle is new Abstract_Handle with null record;

   overriding function Obtain_Handle(Object: File_Handle) return Integer;

end My;

-- my.adb
package body My is

   overriding procedure Initialize(Object: in out Abstract_Handle) is
   begin
      Object.Handle := Obtain_Handle(Abstract_Handle'Class(Object));
   end;

   overriding function Obtain_Handle(Object: File_Handle) return Integer is
   begin
      return 123; -- Suppose 123 is a file handle, for an example
   end;

end My;

-- main.adb
with My;
with Ada.Text_IO;

procedure Main is
   X: My.File_Handle;
begin
   Ada.Text_IO.Put_Line(Integer'Image(X.Handle));
end;


-- 
Victor Porton - http://portonvictor.org


  reply	other threads:[~2014-05-21 14:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-21 13:05 A good program that not compile Victor Porton
2014-05-21 13:49 ` Simon Wright
2014-05-21 14:10   ` Victor Porton
2014-05-21 14:24     ` Victor Porton [this message]
2014-05-21 15:58     ` Simon Wright
replies disabled

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