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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,772ae8afc5db35f2 X-Google-Attributes: gid103376,public From: nospam@thanks.com.au (Don Harrison) Subject: Re: Can't export object of private type Date: 1999/03/03 Message-ID: #1/1 X-Deja-AN: 450577677 Sender: news@syd.csa.com.au X-Nntp-Posting-Host: dev7 References: Organization: CSC Australia, Sydney Reply-To: nospam@thanks.com.au Newsgroups: comp.lang.ada Date: 1999-03-03T00:00:00+00:00 List-Id: Matt Heaney wrote: [Matt's example] Thanks. Your pattern for a hierarchy of singletons is exactly what I'm after. Here is my test program based on your solution: package T is type T_Type (<>) is abstract tagged private; type Access_Class_T_Type is access all T_Type'Class; procedure Display (T: access T_Type) is abstract; function Solo_T return Access_Class_T_Type is abstract; private type T_Type is abstract tagged null record; end; package T.Child is type T_Child_Type (<>) is new T_Type with private; type Access_Class_T_Child_Type is access all T_Child_Type'Class; procedure Display (TC: access T_Child_Type); function Solo_T return Access_Class_T_Child_Type; private type T_Child_Type is new T_Type with null record; Self: aliased T_Child_Type; end; with Text_IO; use Text_IO; package body T.Child is procedure Display (TC: access T_Child_Type) is begin Put_Line ("I am a T_Child object"); end; function Solo_T return Access_Class_T_Child_Type is begin return Self'Access; end; end; package T.Other_Child is ... -- similar end; package body T.Other_Child is ... -- similar end; with T; use T; with T.Child; use T.Child; with T.Other_Child; use T.Other_Child; procedure Use_T is type T_Index_Type is new Integer range 1 .. 2; type T_Array_Type is array (T_Index_Type) of Access_Class_T_Type; T_Array: T_Array_Type := ( 1 => T.Child.Solo_T.all'Access, -- 1) 2 => T.OTher_Child.Solo_T.all'Access); -- 1) begin for I in T_Array'Range loop Display (T_Array(I) ); -- 2) end loop; end; 1) Can this ugly stuff be avoided? 2) Dispatching call. :We have used the features the language provides us to design a type :hierarchy such that, the client must use the singleton instance(s). He :has no other choice in the matter, which is the intended effect. That's what I'm after. -- Don (Harrison). donh at syd.csa.com.au