From: stt@spock.camb.inmet.com (Tucker Taft)
Subject: Re: Deriving from non-null abstract type
Date: 1995/03/29
Date: 1995-03-29T00:00:00+00:00 [thread overview]
Message-ID: <D67M37.J6y@inmet.camb.inmet.com> (raw)
In-Reply-To: 3lbh2q$8ov@israel-info.datasrv.co.il
Moti Ben-Ari (benari@zeus.datasrv.co.il) wrote:
: I would like to derive from a _non-null_ abstract tagged type:
: type Abstract_Type is abstract tagged
: record
: General_Info: Some_Type;
: end record;
: type Derived_Type is new Abstract_Type with
: record
: Special_Info: Some_Other_Type;
: end record;
: Of course, you can't create a value of the abstract type,
: but it turns out that it is impossible to create a value
: of the derived type:
: D: Derived_Type := (G with S);
: because G would have to be an aggregate of an abstract type
: which is illegal.
There is no need to use an extension aggregate at all. You
can use "regular" record aggregates if you are giving all of the
components of a record extension, including those inherited from the
parent type. Hence, the following is the appropriate way to initialize
all of the components of a record extension:
D : Derived_Type :=
(General_Info => General_Value, Special_Info => S);
or positionally:
D : Derived_Type (General_Value, S);
: ... The only thing you can do is:
: D: Derived_Type := (Abstract_Type with S);
: which means that the component General_Info has to
: be initialized in a separate statement.
This kind of aggregate is to be used when you want to
default-initialize the inherited components. If you want
to initialize them, then as indicated above, just use
a regular record aggregate.
: This seems to be against the philosophy of Ada which
: provides aggregates so that you won't forget to initialize
: a component.
: Is there some way of creating a value that I don't see?
Yes -- use a regular record aggregate.
: If not, why aren't abstract types restricted to null records?
See above.
: Moti
: Moti Ben-Ari
: benari@datasrv.co.il
-Tucker Taft stt@inmet.com
Intermetrics, Inc.
next prev parent reply other threads:[~1995-03-29 0:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-03-29 0:00 Deriving from non-null abstract type Moti Ben-Ari
1995-03-29 0:00 ` Robert I. Eachus
1995-03-30 0:00 ` Tucker Taft
1995-03-29 0:00 ` Tucker Taft [this message]
1995-03-30 1:53 ` Dan Johnston D.B.
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox