comp.lang.ada
 help / color / mirror / Atom feed
From: jsa@alexandria.organon.com (Jon S Anthony)
Subject: Re: Class object initialization....
Date: 1997/10/09
Date: 1997-10-09T00:00:00+00:00	[thread overview]
Message-ID: <JSA.97Oct9151617@alexandria.organon.com> (raw)
In-Reply-To: 343BEFFE.200574F6@linkabit.titan.com


In article <343BEFFE.200574F6@linkabit.titan.com> Marc Bejerano <t_mjb@linkabit.titan.com> writes:

> type foo is tagged record
>   a: integer := -1234;
> end record;
> 
> type bar is new foo with record
>   b: natural := 1234;
> end record;
> 
> How would I "initialize" data member 'a' inside of bar? In C++ I would
> do this in the constructor. How would I do this in Ada95? (Can I do this
> in Ada95?)

What do you mean by "inside of bar"??  Wherever the structures are
visible an aggregate takes the place of a C++ constructor:

    X : Bar := (A => 13, B => 31);

or simply

    X : Bar := (13, 31);

or, in a derived case such as this

    X : Bar := (foo with B => 77);

If the structures are not visible, you could use controlled types,
which have user definable initialization procedures per type.  You
might also try discriminants.

/Jon

-- 
Jon Anthony
STL, Belmont, MA 02178, 617.484.3383 
"Nightmares - Ha!  The way my life's been going lately,
 Who'd notice?"  -- Londo Mollari




           reply	other threads:[~1997-10-09  0:00 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <343BEFFE.200574F6@linkabit.titan.com>]
replies disabled

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