From: Shark8 <OneWingedShark@gmail.com>
Subject: Re: How to use read-only variables?
Date: Sat, 03 Jan 2015 19:55:57 -0700
Date: 2015-01-03T19:55:57-07:00 [thread overview]
Message-ID: <9Z1qw.1023124$Lj7.835753@fx22.iad> (raw)
In-Reply-To: <cgrhh9F1465U1@mid.individual.net>
On 03-Jan-15 17:58, hreba wrote:
>
> type R is abstract tagged limited record
> n: access constant Integer;
> end record;
>
> type Rv is new R with private;
>
> private
>
> type Rv is new R with record
> nv: aliased Integer;
> end record;
Try it like this:
With
Ada.Text_IO.Text_Streams;
procedure Test is
package tmp is
type R is abstract tagged limited record
n: access constant Integer;
end record;
type Rv is new R with private;
function Make( I : Integer ) return Rv;
function Val( Item : Rv ) return Integer;
private
type Rv is new R with record
-- The following referenced "this" as a particular
-- instance for the default value by using the type-name
-- (and 'access) as a self-reference. we have to convert
-- the de-reference to the parent class, and then access
-- the appropriate value.
nv: aliased Integer:= R(Rv'access.all).n.all;
end record;
-- Note that we let the default values take care of ensuring
-- that the values are properly in-sync.
function Make( I : Integer ) return Rv is
( n => new Integer'(I), others => <> );
function Val( Item : Rv ) return Integer is
( Item.nv );
end tmp;
use Ada.Text_IO;
begin
declare
K : tmp.Rv:= tmp.make( 129 );
begin
Put_Line( "K.n:" & K.Val'Img );
end;
Put_Line( "Done." );
end Test;
next prev parent reply other threads:[~2015-01-04 2:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-04 0:58 How to use read-only variables? hreba
2015-01-04 1:50 ` Hubert
2015-01-04 2:04 ` Hubert
2015-01-04 2:33 ` Brad Moore
2015-01-04 2:55 ` Shark8 [this message]
2015-01-04 12:56 ` hreba
2015-01-04 15:34 ` sbelmont700
2015-01-04 20:45 ` Brad Moore
2015-01-04 20:48 ` Brad Moore
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox