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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f7a9613bbc2bd8c9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-13 09:44:17 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Generic default parameters Date: 13 May 2002 12:42:45 -0400 Organization: NASA Goddard Space Flight Center (skates.gsfc.nasa.gov) Message-ID: References: <60lvdu4ifauunm4qob6ir7rlas4soe0cp4@4ax.com> NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 1021308566 26532 128.183.220.71 (13 May 2002 16:49:26 GMT) X-Complaints-To: usenet@news.gsfc.nasa.gov NNTP-Posting-Date: 13 May 2002 16:49:26 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:23965 Date: 2002-05-13T16:49:26+00:00 List-Id: Dmitry A. Kazakov writes: > A concrete example. Let we want to implement smart pointers / handles. > It could go as follows: > > package Object is > type Entity is new > Ada.Finalization.Limited_Controlled with > record > Use_Count : Natural := 0; -- Reference count > end record; > ... > end Object; > > generic > type Object_Type (<>) is abstract new Entity with private; > type Object_Type_Ptr is access all Object_Type'Class; > package Object.Handle is > type Handle is tagged private; > ... > private > type Handle is new Ada.Finalization.Controlled with record > Ptr : Object_Type_Ptr := null; > end record; > end Object.Handle; > > Now the problem, how to instantiate Object.Handle having Object_Type > private? Let we have: > > package IO is > ... > private > type File_Descriptor is new Entity with ...; > type File_Descriptor_Ptr is access all File_Descriptor'Class; > end IO; > > package IO.Handles is > package Handles is > new Object.Handle (File_Descriptor, File_Descriptor_Ptr); > -- Illegal, File_Descriptor is not visible here > subtype IO_Handle is Handles.Handle; > ... > end IO.Handles; Simple. Make IO.Handles a private package: private package IO.Handles is Now the only places IO.Handles.IO_Handles can be seen are the same places IO.File_Descriptor can be seen. Hmm, perhaps you _wanted_ IO.Handles.IO_Handle to be public, so clients could do stuff. Simple : with Object.Handle; package IO.Handles is type IO_Handle is private; private package Handles is new Object.Handle (File_Descriptor, File_Descriptor_Ptr); -- Illegal, File_Descriptor is not visible here type IO_Handle is new Handles.Handle with null record; end IO.Handles; -- -- Stephe