From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,40d95f0abf698cd9 X-Google-Attributes: gid103376,public Path: controlnews3.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed.mathworks.com!news.tele.dk!news.tele.dk!small.news.tele.dk!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: [Newbie] Visibility parent-child Date: Wed, 12 May 2004 08:00:41 +0200 Organization: AdaCL Message-ID: <1556665.YxULaKypU3@linux1.krischik.com> References: <40a0fc28$0$31944$626a14ce@news.free.fr> Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1084343517 01 19092 1mX2GeHvNDTWmkH 040512 06:31:57 X-Complaints-To: usenet-abuse@t-online.de X-ID: r6w+naZF8ewVN0Kkq7Iu4hhcXK9vJFNLQg6KGVYAZpvZSj0J2uahUn User-Agent: KNode/0.7.7 Xref: controlnews3.google.com comp.lang.ada:464 Date: 2004-05-12T08:00:41+02:00 List-Id: 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