comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic.brenta@insalien.org>
Subject: Re: access private element of base-class
Date: Sat, 02 Oct 2004 13:32:07 +0200
Date: 2004-10-02T13:35:27+02:00	[thread overview]
Message-ID: <87mzz5s6dk.fsf@insalien.org> (raw)
In-Reply-To: sa4pt41by9o.fsf@snoopy.apana.org.au

Brian May writes:
>>>>>> "Rick" == Rick Santa-Cruz writes:
>
>     >>> In C++ talk: Protection in Ada work on the "namespace" and not
>     >>> on the "class". This needs some getting use to but has the
>     >>> advantage that it works with classic (non OO) programming as
>     >>> well.
>     >>  It also eliminates the need for "friends", an ugly kludge.
>
>     Rick> Why this?
>
> In Ada you can put multiple "classes" in one package. Hence there is
> no need to use "friends".
>
> This isn't as flexible at C++ friends, where you can make any class a
> friend, but I have also heard complaints that C++ friends are too
> flexible, making code complicated.

You can also place things in child packages; these things can see the
private part of the parent package's spec.  By declaring a subprogram
in the private part of the spec, you get the effect of the C++
"protected", not only for child classes but for everything declared in
child packages.  "Things" may be types and subprograms. For example:

package P is
   type T is tagged private;
   procedure Foo (This : in T);
private
   type T is tagged record
      Member : Integer;
   end record;
   function Protected (This : in T) return Integer;
end P;

package P.Q is
   procedure Friend_Proc (That : in out T);
end P.Q;

package body P.Q is
   procedure Friend_Proc (That : in out T) is
   begin
      P.Foo (That);
      That.Member := P.Protected (That);
   end Friend_Proc;
end P.Q;

-- 
Ludovic Brenta.



  reply	other threads:[~2004-10-02 11:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-01  0:35 access private element of base-class Rick Santa-Cruz
2004-10-01  0:54 ` Jeffrey Carter
2004-10-01  7:45   ` Martin Krischik
2004-10-01 17:54     ` Jeffrey Carter
2004-10-01 17:58       ` Rick Santa-Cruz
2004-10-02  3:21         ` Brian May
2004-10-02 11:32           ` Ludovic Brenta [this message]
2004-10-02 13:56             ` Nick Roberts
2004-10-03 18:51           ` Jeffrey Carter
replies disabled

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