comp.lang.ada
 help / color / mirror / Atom feed
* access private element of base-class
@ 2004-10-01  0:35 Rick Santa-Cruz
  2004-10-01  0:54 ` Jeffrey Carter
  0 siblings, 1 reply; 9+ messages in thread
From: Rick Santa-Cruz @ 2004-10-01  0:35 UTC (permalink / raw)


Hi,

again something with Ada is unclear to me. In the thread:
http://groups.google.de/groups?q=ada+protected+c%2B%2B&hl=de&lr=&ie=UTF-8&selm=slrn8ljk2n.qv2.gisle%40struts.ii.uib.no&rnum=6
I read, that the Ada-private is more similar to protected than to C++ 
private, so I tried the following:

-- specification of Base-Class
package Base_Class is
    type Base is tagged private;

    private
        type Base is tagged
        record
            Number: Integer;
        end record;
end Base_Class;

-- specification of Derived-Class
with Base_Class;
use Base_Class;
package Derived_Class is
 type Derived is new Base with private;

 procedure Derived_Proc(D: in out Derived; Num :Integer);
 private
  type Derived is new Base with
   null record;
end Derived_Class;

-- body of Derived-Class
package body Derived_Class is
 procedure Derived_Proc(D: in out Derived; Num :Integer) is
 begin
  D.Number := Num; -- here I get a compiler error. Why?
 end Derived_Proc;
end Derived_Class;

Why can't I access Number which is a private-Element of the Base-Class?

Thanks for any help,
Rick 





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: access private element of base-class
  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
  0 siblings, 1 reply; 9+ messages in thread
From: Jeffrey Carter @ 2004-10-01  0:54 UTC (permalink / raw)


Rick Santa-Cruz wrote:
> 
> I read, that the Ada-private is more similar to protected than to C++ 
> private, so I tried the following:

It's like C++'s "protected" because the full view is visible in

A private child package

The private part and body of a public child package

Since you don't have a child package, private is private in your 
package; the full view is not visible outside the package and its children.

-- 
Jeff Carter
"Perfidious English mouse-dropping hoarders."
Monty Python & the Holy Grail
10




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: access private element of base-class
  2004-10-01  0:54 ` Jeffrey Carter
@ 2004-10-01  7:45   ` Martin Krischik
  2004-10-01 17:54     ` Jeffrey Carter
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Krischik @ 2004-10-01  7:45 UTC (permalink / raw)


Jeffrey Carter wrote:

> Rick Santa-Cruz wrote:
>> 
>> I read, that the Ada-private is more similar to protected than to C++
>> private, so I tried the following:
> 
> It's like C++'s "protected" because the full view is visible in
> 
> A private child package
> 
> The private part and body of a public child package
> 
> Since you don't have a child package, private is private in your
> package; the full view is not visible outside the package and its
> children.

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.

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: access private element of base-class
  2004-10-01  7:45   ` Martin Krischik
@ 2004-10-01 17:54     ` Jeffrey Carter
  2004-10-01 17:58       ` Rick Santa-Cruz
  0 siblings, 1 reply; 9+ messages in thread
From: Jeffrey Carter @ 2004-10-01 17:54 UTC (permalink / raw)


Martin Krischik wrote:

> 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.

-- 
Jeff Carter
"You cheesy lot of second-hand electric donkey-bottom biters."
Monty Python & the Holy Grail
14




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: access private element of base-class
  2004-10-01 17:54     ` Jeffrey Carter
@ 2004-10-01 17:58       ` Rick Santa-Cruz
  2004-10-02  3:21         ` Brian May
  0 siblings, 1 reply; 9+ messages in thread
From: Rick Santa-Cruz @ 2004-10-01 17:58 UTC (permalink / raw)



"Jeffrey Carter" <spam@spam.com> schrieb im Newsbeitrag 
news:zRg7d.412$M05.293@newsread3.news.pas.earthlink.net...
> Martin Krischik wrote:
>
>> 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.
Why this? 





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: access private element of base-class
  2004-10-01 17:58       ` Rick Santa-Cruz
@ 2004-10-02  3:21         ` Brian May
  2004-10-02 11:32           ` Ludovic Brenta
  2004-10-03 18:51           ` Jeffrey Carter
  0 siblings, 2 replies; 9+ messages in thread
From: Brian May @ 2004-10-02  3:21 UTC (permalink / raw)


>>>>> "Rick" == Rick Santa-Cruz <rick_santa_cruz75@msn.com> 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.
-- 
Brian May <bam@snoopy.apana.org.au>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: access private element of base-class
  2004-10-02  3:21         ` Brian May
@ 2004-10-02 11:32           ` Ludovic Brenta
  2004-10-02 13:56             ` Nick Roberts
  2004-10-03 18:51           ` Jeffrey Carter
  1 sibling, 1 reply; 9+ messages in thread
From: Ludovic Brenta @ 2004-10-02 11:32 UTC (permalink / raw)


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.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: access private element of base-class
  2004-10-02 11:32           ` Ludovic Brenta
@ 2004-10-02 13:56             ` Nick Roberts
  0 siblings, 0 replies; 9+ messages in thread
From: Nick Roberts @ 2004-10-02 13:56 UTC (permalink / raw)


I think the rules can be summarised as follows.

For a public child package:
    - for its specification :
       - the visible part can see the visible part of its parent's spec
       - the private part can see all of the specification of its parent
    - its body can see all of the specification of its parent
    - public and private siblings can see the visible part of its spec
      (if they mention it in a 'with' clause)

For a private child package:
    - for its specification :
       - the visible and private parts can see all of it's parent's spec
    - its body can see all of the specification of its parent
    - only private siblings can see the visible part of its specification
      (if they mention it in a 'with' clause)

Phew, I hope this is right!

-- 
Nick Roberts



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: access private element of base-class
  2004-10-02  3:21         ` Brian May
  2004-10-02 11:32           ` Ludovic Brenta
@ 2004-10-03 18:51           ` Jeffrey Carter
  1 sibling, 0 replies; 9+ messages in thread
From: Jeffrey Carter @ 2004-10-03 18:51 UTC (permalink / raw)


Brian May wrote:

> In Ada you can put multiple "classes" in one package. Hence there is
> no need to use "friends".

I was thinking of child packages, which have visibility, in their 
private parts and bodies, to the parent's private part. Thus, a child 
has the same visibility as a "friend", without the parent having to name 
or even know about the child.

-- 
Jeff Carter
"English bed-wetting types."
Monty Python & the Holy Grail
15




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-10-03 18:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2004-10-02 13:56             ` Nick Roberts
2004-10-03 18:51           ` Jeffrey Carter

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