From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Extending a type and Finalization
Date: Fri, 5 Jun 2009 05:21:28 -0700 (PDT)
Date: 2009-06-05T05:21:28-07:00 [thread overview]
Message-ID: <b969c933-7071-4517-a82e-c15836588188@r33g2000yqn.googlegroups.com> (raw)
In-Reply-To: 5dbd97d8-ab49-4316-b531-23b28fc2af7b@k8g2000yqn.googlegroups.com
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.
next prev parent reply other threads:[~2009-06-05 12:21 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 [this message]
2009-06-05 13:02 ` malaise
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