comp.lang.ada
 help / color / mirror / Atom feed
From: Martin Krischik <krischik@users.sourceforge.net>
Subject: Re: [Newbie] Visibility parent-child
Date: Wed, 12 May 2004 08:00:41 +0200
Date: 2004-05-12T08:00:41+02:00	[thread overview]
Message-ID: <1556665.YxULaKypU3@linux1.krischik.com> (raw)
In-Reply-To: 40a0fc28$0$31944$626a14ce@news.free.fr

PG wrote:

> I can't access the child'types and I don't know why.
 
> -- parent package specification
> package Parent is
>     blabla;
> end Parent;
> -- + body
> 
> -- child package specification
> package Parent.Child is
>     type Object is private;
>     procedure Add (Ob: Object);
> private
>     type Object is
>         record
>             ...
>         end record;
> end Parent.Child;
> -- + body
> 
> In a client program,  I import these 2 packages:
> with Parent, Parent.Child;
> use Parent, Parent.Child;

Sadly most tutorial do not point out the alternatives for "use". Unlike
"with" "use" can be used anywhere in the program:

with Parent, Parent.Child;

package body Client is
  use Parent;
  use type Parent.Child.Object;
....
  procedure P is
    use Parent.Child;
...

end Client;

> ...
> So, the procedure Add is visible but not the type Object !
> When I declare :        Ob: Object;
> it detects an error: "Object" is not visible.

Well, from what I see Object should be visible. But maybe a side effect
combined with an unhelpful compiler message. That's when excessive use of
"use" has made more then one Object is visible.

> When I declare with the prefix, it's OK: Ob: Parent.Child.Object;

Replace "use" with a "package rename" and "use type":

package C renames Parent.Child;
use type Parent.Child.Object;

then you can say:

Ob: C.Object;
C.Add (Ob);

This is the better option when many types are called "Object".

Or you switch to the Types.Type school:

package Parents.Childs is
  type Child is private;

Or the Type.Type_Type school:

package Parent.Child is
  type Child_Type is private;

Currently you are using the Class.Object school which are normally used in
object orientated programming:

package Parent.Child is
  type Object is tagged private;

All three schools are generally accepted in the Ada comunity.

With Regards

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




      parent reply	other threads:[~2004-05-12  6:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-11 16:15 [Newbie] Visibility parent-child PG
2004-05-11 18:29 ` Georg Bauhaus
2004-05-11 18:46   ` PG
2004-05-12  9:32     ` Martin Krischik
2004-05-12  6:00 ` Martin Krischik [this message]
replies disabled

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