comp.lang.ada
 help / color / mirror / Atom feed
From: malaise@magic.fr
Subject: Re: Extending a type and Finalization
Date: Fri, 5 Jun 2009 06:02:06 -0700 (PDT)
Date: 2009-06-05T06:02:06-07:00	[thread overview]
Message-ID: <3d991397-94e5-4dd5-8712-a1fe5b1d234c@t21g2000yqi.googlegroups.com> (raw)
In-Reply-To: b969c933-7071-4517-a82e-c15836588188@r33g2000yqn.googlegroups.com

On 5 juin, 14:21, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
> Pascal Malaise wrote on comp.lang.ada:
>
>
>
> > I declare P.T as "new Ada.Finalization.Controlled with record ..." and
> > I don't define Finalize for it.
> > Then in Pp I declare Tt as "new P.T with record ..." and I declare an
> > overriding procedure Finalize (V : in out Tt) and its body in Pp body.
> > It does not compile, with error: 'subprogram "Finalize" is not
> > overriding'
>
> > Same if I define in P a Finalize for T.
>
> > Any idea?
>
> > ------------------------------
> > with Ada.Finalization;
> > package P is
> >   type T is tagged private;
> > private
> >   type T is new Ada.Finalization.Controlled with record
> >     I : Integer;
> >   end record;
> > end P;
>
> > with P;
> > package Pp is
> >   type Tt is tagged private;
> > private
> >   type Tt is new P.T with record
> >     Ii : Integer;
> >   end record;
> >   overriding procedure Finalize (V : in out Tt);
> > end Pp;
>
> > package body Pp is
> >   overriding procedure Finalize (V : in out Tt) is
> >   begin
> >     null;
> >   end Finalize;
> > end Pp;
>
> That's because P.T is a *private* record extension of
> Ada.Finalization.Controlled. Package PP cannot see that P.T derives
> from it.
>
> Solution 1: rename PP to P.P, a child package of P so it can see the
> private part of P.
>
> Solution 2: make P.T a public record extension:
>
> type T is new Ada.Finalization.Controlled with private;
>
> But I recommend that you *not* derive P.T from any other type; use a
> mixin instead. Making a type controlled is not a good enough reason
> for making it tagged.
>
> --
> Ludovic Brenta.

Thank you Ludovic. Solution 2 is fine for me.

Concerning your recommendation, I think that the following is
compliant, or did I misunderstand something?
type T is new Ada.Finalization.Controlled with record
    I : Integer;
  end record;
end P;



  reply	other threads:[~2009-06-05 13:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-04 17:45 Extending a type and Finalization pascal.malaise
2009-06-04 18:00 ` Hibou57 (Yannick Duchêne)
2009-06-04 19:33   ` Adam Beneschan
2009-06-04 20:06     ` Dmitry A. Kazakov
2009-06-04 21:18       ` Adam Beneschan
2009-06-05  9:11         ` Dmitry A. Kazakov
2009-06-05 14:48           ` Adam Beneschan
2009-06-05 17:15             ` Dmitry A. Kazakov
2009-06-05 11:29     ` malaise
2009-06-05 12:21       ` Ludovic Brenta
2009-06-05 13:02         ` malaise [this message]
2009-06-05 13:14           ` Ludovic Brenta
2009-06-05 13:32             ` malaise
2009-06-15  6:30 ` AdaMagica
replies disabled

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