comp.lang.ada
 help / color / mirror / Atom feed
* [Newbie] Visibility parent-child
@ 2004-05-11 16:15 PG
  2004-05-11 18:29 ` Georg Bauhaus
  2004-05-12  6:00 ` Martin Krischik
  0 siblings, 2 replies; 5+ messages in thread
From: PG @ 2004-05-11 16:15 UTC (permalink / raw)


Hi,

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;
...
So, the procedure Add is visible but not the type Object !
When I declare :        Ob: Object;
it detects an error: "Object" is not visible.
When I declare with the prefix, it's OK: Ob: Parent.Child.Object;

I don't know why the type Object is not directly visible without prefix ?

Thanks for your help.

Patrick





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

* Re: [Newbie] Visibility parent-child
  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  6:00 ` Martin Krischik
  1 sibling, 1 reply; 5+ messages in thread
From: Georg Bauhaus @ 2004-05-11 18:29 UTC (permalink / raw)


PG <leviquet@free.fr> wrote:
 
: In a client program,  I import these 2 packages:
: with Parent, Parent.Child;
: use Parent, Parent.Child;
: ...
: So, the procedure Add is visible but not the type Object !
: When I declare :        Ob: Object;
: it detects an error: "Object" is not visible.
: When I declare with the prefix, it's OK: Ob: Parent.Child.Object;

Is there a type "Object" other than the one from Parent.Child
which hides the one you expected? My compiler has no complaints.

--  Georg



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

* Re: [Newbie] Visibility parent-child
  2004-05-11 18:29 ` Georg Bauhaus
@ 2004-05-11 18:46   ` PG
  2004-05-12  9:32     ` Martin Krischik
  0 siblings, 1 reply; 5+ messages in thread
From: PG @ 2004-05-11 18:46 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 883 bytes --]

Thanks for your help.

No, there is no other "Object" which hide this one. But the real problem
was, I suppose, I nammed the package like the type.

package Parent.Object is
    type object is...

I don't knew it was prohibited...

"Georg Bauhaus" <sb463ba@l1-hrz.uni-duisburg.de> a �crit dans le message de
news:c7r61v$haa$1@a1-hrz.uni-duisburg.de...
> PG <leviquet@free.fr> wrote:
>
> : In a client program,  I import these 2 packages:
> : with Parent, Parent.Child;
> : use Parent, Parent.Child;
> : ...
> : So, the procedure Add is visible but not the type Object !
> : When I declare :        Ob: Object;
> : it detects an error: "Object" is not visible.
> : When I declare with the prefix, it's OK: Ob: Parent.Child.Object;
>
> Is there a type "Object" other than the one from Parent.Child
> which hides the one you expected? My compiler has no complaints.
>
> --  Georg





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

* Re: [Newbie] Visibility parent-child
  2004-05-11 16:15 [Newbie] Visibility parent-child PG
  2004-05-11 18:29 ` Georg Bauhaus
@ 2004-05-12  6:00 ` Martin Krischik
  1 sibling, 0 replies; 5+ messages in thread
From: Martin Krischik @ 2004-05-12  6:00 UTC (permalink / raw)


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




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

* Re: [Newbie] Visibility parent-child
  2004-05-11 18:46   ` PG
@ 2004-05-12  9:32     ` Martin Krischik
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Krischik @ 2004-05-12  9:32 UTC (permalink / raw)


PG wrote:

> Thanks for your help.
> 
> No, there is no other "Object" which hide this one. But the real problem
> was, I suppose, I nammed the package like the type.
> 
> package Parent.Object is
>     type object is...
> 
> I don't knew it was prohibited...

It is not at all prohibited. You just have to know that when you use a name
twice one might hide the other. And then you have to prefix to get access
to the hidden one.

With Regards

Martin

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




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

end of thread, other threads:[~2004-05-12  9:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox