From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a072745e2e39f048 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-10 04:56:26 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mark_doherty@yahoo.co.uk (Mark Doherty) Newsgroups: comp.lang.ada Subject: Re: Different initial values for derived type? Date: 10 Nov 2003 04:56:25 -0800 Organization: http://groups.google.com Message-ID: <5e3e03a7.0311100456.1b41c70a@posting.google.com> References: NNTP-Posting-Host: 81.132.188.199 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1068468985 30727 127.0.0.1 (10 Nov 2003 12:56:25 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 10 Nov 2003 12:56:25 +0000 (UTC) Xref: archiver1.google.com comp.lang.ada:2292 Date: 2003-11-10T04:56:25-08:00 List-Id: Stefan Soos wrote in message news:... > Hello, > > I've got the following type definition > > type Object_Type is tagged > record > Name : Character := '?'; > Score : Natural := 0; > X : Positive := 1; > Y : Positive := 1; > end record; > Now I'd like to have a derived type with the same components > but with different initial Values. Do I have to use discriminants for > all of my components or can I say something like > > type Derived_Type is new Object_Type with ( Name => '!', > Score => 10); > I know, I can't because it doesn't compile, but is there a > similar approach? > > > Thanks in advance, > Stefan > > -- you could use controlled types if performance is not an issue... with ada.finalization; use ada.finalization; package controlled_types is type Object_Type is new controlled with record Name : Character; end record; procedure initialize (object : in out object_type); procedure ADJUST (object : in out object_type); procedure finalize (object : in out object_type); type Derived_Type is new Object_Type with null record; procedure initialize (object : in out derived_type); procedure ADJUST (object : in out derived_type); procedure finalize (object : in out derived_type); end ; package body controlled_types is procedure initialize (object : in out object_type) is begin object := ( controlled with Name => '?'); end; procedure ADJUST (object : in out object_type) is begin null; end; procedure finalize (object : in out object_type) is begin null; end; procedure initialize (object : in out derived_type) is begin object := (controlled with Name => '!'); end; procedure ADJUST (object : in out derived_type) is begin null; end; procedure finalize (object : in out derived_type) is begin null; end; end ; with controlled_types; use controlled_types; with ada.text_io; use ada.text_io; procedure controlled_test is o : object_type; d : derived_type; begin put_line("name => " & o.name); put_line("name => " & d.name); end;