comp.lang.ada
 help / color / mirror / Atom feed
From: Christoph Grein <christoph.grein@eurocopter.com>
Subject: Re: scope and visibility
Date: Wed, 27 Feb 2002 08:00:48 +0100 (MET)
Date: 2002-02-27T08:00:48+01:00	[thread overview]
Message-ID: <mailman.1014793322.24846.comp.lang.ada@ada.eu.org> (raw)

> but I'm having quite a hard time with 'private' and friends.

The Ada keyword 'private' means that you do not see into the thing denoted as 
private.

Thus a private type hides its details, you do not see them and cannot assume 
anything about them.
'private' in a package hides anything behind from visibility outside this 
hierarchy.

package P is

  type T is private;

  ...operations...

private

  type T is new Integer;

end P;

If you're outside of P, you cannot make use of the fact that T is an integer. It 
could be anything (array, record, ...) that is not limited (another Ada 
keyword).

Inside of P, after the keyword 'private' and also in the body, you of course can 
use the fact that T is Integer. This is also true for children of P.

private package P.Priv_Child is

  -- You see the private part of P here.

private

end P.Priv_Child;

package P.Child is

  -- You do not see the private part of P here.

private

  -- You see the private part of P here.

end P.Child;

This is approximately like (but there _are_ differences):

package P is

  type T is private;

  ...operations...

  package Child is
    ...
  end Child;

private

  type T is new Integer;

  package Priv_Child is
    ...
  end Priv_Child;

end P;



Now try

package P.Priv_Child.Grand_Child is ...

private P.Priv_Child.Priv_Grand_Child is ...

package P.Child.Grand_Child is ...

private P.Child.Priv_Grand_Child is ...

These all have different visibilities.


generic
  type T is private;
package P is
  -- You cannot assume anything about P except that it's not limited and
  -- that it is definite.
end P;



             reply	other threads:[~2002-02-27  7:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-27  7:00 Christoph Grein [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-02-27  4:00 scope and visibility Dave Poirier
2002-02-27 15:19 ` Jim Rogers
2002-02-27 22:47   ` chris.danx
replies disabled

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