comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic.brenta@insalien.org>
Subject: Re: Problems with tagged records and inheritance
Date: 11 Jul 2003 00:29:52 +0200
Date: 2003-07-11T00:29:52+02:00	[thread overview]
Message-ID: <m37k6qhv6n.fsf@insalien.org> (raw)
In-Reply-To: bekkpr$12eg$1@ulysses.noc.ntua.gr

"Papastefanos Serafeim" <serafeim@otenet.gr> writes:

> The error is becouse AAA is not part of Child.
> Why is that ? I thought that Child would contain
> AAA and BBB, and not only BBB...

I don't have all the details of your program, but I suspect that:

- you have declared the two types Base and Child in different packages

- you have defined the full view of Base in Base's private part

- and that the package containing Child is not a child package of the
  one where you defined Base.

This would explain that your Test procedure can only see the part of
the Ch object that is declared in the same package.  The part
inherited from Base is private.

If you want the Test procedure to see the internal details of Base,
you must either declare Child in a child package or in the same
package as Base.

On the other hand, this would break encapsulation; is this really what
you want?  Here is a solution that does not break encapsulation:

package One is
   type Base is tagged private;
   procedure Test (B : in Base);
private
   type Base is tagged record  -- The full view is private
      Aaa : Integer;
   end record;
end One;

package body One is
   procedure Test (B : in Base) is
   begin
      Put (B.Aaa);
   end Test;
end One;

with One; use One;
package Two is
   --  Package Two is not a child of package One; therefore it cannot
   --  see the private part of package One.
   type Child is new Base with private;

   procedure Test (Ch : in Child);
private
   type Child is new Base with record
      Bbb : Integer;
   end record;
end Infant;


package body Two is
   procedure Test (Ch : in Child) is
   begin
      One.Test (Base (Ch)); -- Delegate processing of invisible part
      --  Now, process the visible part:
      Put (Ch.Bbb);
   end Test;
end Two;


HTH

-- 
Ludovic Brenta.



  parent reply	other threads:[~2003-07-10 22:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-10 20:56 Problems with tagged records and inheritance Papastefanos Serafeim
2003-07-10 22:15 ` Re; " tmoran
2003-07-10 22:24 ` Robert I. Eachus
2003-07-10 22:29 ` Ludovic Brenta [this message]
2003-07-11 11:56   ` Marin David Condic
2003-07-11 11:49 ` Papastefanos Serafeim
2003-07-15  1:34 ` Richard Riehle
replies disabled

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