comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@world.std.com>
Subject: Re: allocators for classwide types?
Date: 1999/12/28
Date: 1999-12-28T00:00:00+00:00	[thread overview]
Message-ID: <wcciu1j18dx.fsf@world.std.com> (raw)
In-Reply-To: 38684DEE.6CB6F268@telepath.com

Ted Dennison <dennison@telepath.com> 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




  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 allocators for classwide types? Ted Dennison
1999-12-28  0:00 ` Robert A Duff [this message]
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