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.3 required=5.0 tests=BAYES_00,INVALID_MSGID 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: Matthew Heaney Subject: Re: Can't export object of private type Date: 1999/03/02 Message-ID: #1/1 X-Deja-AN: 450259512 Sender: matt@mheaney.ni.net References: <7b1k4h$13k6@news3.newsguy.com> <36daf246.1947172@news.pacbell.net> <36db6723.31869063@news.pacbell.net> NNTP-Posting-Date: Mon, 01 Mar 1999 22:11:50 PDT Newsgroups: comp.lang.ada Date: 1999-03-02T00:00:00+00:00 List-Id: tmoran@bix.com (Tom Moran) writes: > >No. If you make the type limited and indefinite, no one outside the > >package can create an instance. > But given such a type T, if I'm outside and make > type Son_Of_T is new T with ... > how can I create an object of type Son_Of_T, and if such an object > cannot be created, of what use is Son_Of_T? The question is wrong. There's no such thing as "being outside" and declaring a derived type. If there is a derived type, it's within the package hierarchy: package P is type T (<>) is abstract tagged limited private; procedure Op (O : access T) is abstract; private type T is abstract tagged limited null record; end P; package P.C is type NT is new T with private; procedure Op (O : access NT); type NT_Access is access all NT; function Singleton return NT_Access; private type NT is new T with null record; end; package body P.C is O : aliased NT; procedure Op (O : access NT) is begin null; end; function Singleton return NT_Access is begin return O'Access; end; end; When I try to declare an instance of P.C.NT: with P.C; procedure Test_P is O : P.C.NT; begin null; end; I get the following error: gnatf -x5 /home/matt/test_p.adb test_p.adb:4:10: unconstrained subtype not allowed (need initialization) But within the package hierarchy, I'm free to declare instances of the type (see the body of P.C), because I have privileged access to the representation of the type (which of course, is _not_ indefinite). We can get rid of the compiler diagnostic, by using the singleton instance: with P.C; use P.C; procedure Test_P is begin Op (Singleton); end; 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.