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,start X-Google-Attributes: gid103376,public From: Ted Dennison Subject: allocators for classwide types? Date: 1999/12/28 Message-ID: <38684DEE.6CB6F268@telepath.com>#1/1 X-Deja-AN: 565562842 Content-Transfer-Encoding: 7bit X-Accept-Language: en,pdf Content-Type: text/plain; charset=us-ascii X-Complaints-To: Abuse Role , We Care X-Trace: newshog.newsread.com 946359579 216.14.8.17 (Tue, 28 Dec 1999 00:39:39 EST) Organization: Telepath Systems (telepath.com) MIME-Version: 1.0 NNTP-Posting-Date: Tue, 28 Dec 1999 00:39:39 EST Newsgroups: comp.lang.ada Date: 1999-12-28T00:00:00+00:00 List-Id: 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 begin return (Field_1 => new P1_Class'(F1), Field_2 => new P2_Class'(F2) ); end Get; Gnat actually generates a compiler error on my variant of this. 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. However, what I'm trying to do does make sense, as the program could figure out the actual type at runtime. Either way, I take it the above code is somehow not legal? Is there a trick I can use to get around this, or are my clients going to be stuck doing their own dynamic allocations? -- T.E.D. mailto:dennison@telepath.com WWW - http://www.telepath.com/dennison/Ted/TED.html