* Re: Class object initialization....
[not found] <343BEFFE.200574F6@linkabit.titan.com>
@ 1997-10-09 0:00 ` Jon S Anthony
0 siblings, 0 replies; only message in thread
From: Jon S Anthony @ 1997-10-09 0:00 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] only message in thread