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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,aaec211ca305e5ee X-Google-Attributes: gid103376,public From: Robert A Duff Subject: Re: allocators for classwide types? Date: 1999/12/28 Message-ID: #1/1 X-Deja-AN: 565658362 Sender: bobduff@world.std.com (Robert A Duff) References: <38684DEE.6CB6F268@telepath.com> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.lang.ada Date: 1999-12-28T00:00:00+00:00 List-Id: Ted Dennison writes: > I have a situation where I'd like to create a convienence routine that > takes in two objects of classwide types, allocates objects of the > appropriate type with a copy of those parameter values, then puts both > objects in a record which gets returned to the user. > > The thing is, it doesn't look like the language provides any way to > express initialized allocation from classwide parameters. For example, I > would like to do the following: > > > subtype P1_Class is Package_1.Instance'Class; > subtype P2_Class is Package_2.Instance.Class; > type P1_Handle is access all P1_Class; > type P2_Handle is access all P2_Class; > type Descriptor is record > Field_1 : P1_Handle; > Field_2 : P2_Handle; > end record; > . > . > . > function Get (F1 : in P1_Class; > F2 : in P2_Class := Package_2.Get > ) return Recognizable_Token is ^^^^^^^^^^^^^^^^^^ You mean "Descriptor" here? > begin > return (Field_1 => new P1_Class'(F1), > Field_2 => new P2_Class'(F2) > ); > end Get; Your code looks OK to me. > Gnat actually generates a compiler error on my variant of this. ... You should post the text of the message. >... Thinking > about it logicly (often a mistake, but I like to do it anyway), the LRM > does not seem to specificly disallow this. P1_Class and P2_Class *are* > subtype indications. But it would also make absolutely no sense to do a > "new P1_Class;" (without the initilizing value) because it would have > idea how much space to allocate. That's right -- you have to initialize it, as you did. >... However, what I'm trying to do does > make sense, as the program could figure out the actual type at runtime. Right. - Bob