comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison <dennison@telepath.com>
Subject: allocators for classwide types?
Date: 1999/12/28
Date: 1999-12-28T00:00:00+00:00	[thread overview]
Message-ID: <38684DEE.6CB6F268@telepath.com> (raw)

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






             reply	other threads:[~1999-12-28  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-28  0:00 Ted Dennison [this message]
1999-12-28  0:00 ` allocators for classwide types? Robert A Duff
1999-12-28  0:00   ` Ted Dennison
1999-12-28  0:00     ` Ted Dennison
2000-01-06  0:00       ` Robert A Duff
2000-01-07  0:00         ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox