comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Can't export object of private type
Date: 1999/03/02
Date: 1999-03-02T00:00:00+00:00	[thread overview]
Message-ID: <m3emn876zf.fsf@mheaney.ni.net> (raw)
In-Reply-To: 36db6723.31869063@news.pacbell.net

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.





  reply	other threads:[~1999-03-02  0:00 UTC|newest]

Thread overview: 128+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <F7JoCB.JxB@syd.csa.com.au>
1999-02-24  0:00 ` Can't export object of private type Don Harrison
1999-02-24  0:00   ` Tom Moran
1999-02-24  0:00   ` Samuel Mize
1999-02-24  0:00     ` Tucker Taft
1999-02-25  0:00     ` Don Harrison
1999-02-25  0:00       ` robert_dewar
1999-02-26  0:00         ` Don Harrison
1999-02-26  0:00           ` robert_dewar
1999-02-26  0:00             ` bourguet
1999-02-26  0:00               ` Samuel T. Harris
1999-02-27  0:00                 ` Jean-Pierre Rosen
1999-02-27  0:00                 ` Simon Wright
1999-02-28  0:00               ` dewar
1999-03-01  0:00                 ` bourguet
1999-02-26  0:00             ` dennison
1999-03-01  0:00             ` Stephen Leake
1999-03-01  0:00             ` Don Harrison
1999-03-01  0:00               ` robert_dewar
1999-03-03  0:00                 ` Don Harrison
1999-03-03  0:00                   ` robert_dewar
1999-02-27  0:00         ` Brian Rogoff
1999-03-01  0:00           ` robert_dewar
1999-02-25  0:00       ` fraser
1999-02-26  0:00         ` Don Harrison
     [not found]           ` <7b6nqe$75m$1@remarq.com>
1999-02-26  0:00             ` fraser
1999-02-27  0:00               ` Nick Roberts
1999-02-26  0:00           ` fraser
1999-03-01  0:00             ` Don Harrison
1999-03-01  0:00               ` Matthew Heaney
1999-02-26  0:00           ` Samuel Mize
1999-03-01  0:00             ` Don Harrison
1999-03-01  0:00               ` Matthew Heaney
1999-03-02  0:00               ` fraser
1999-03-03  0:00                 ` Don Harrison
1999-02-28  0:00           ` Matthew Heaney
1999-02-28  0:00         ` Matthew Heaney
1999-02-25  0:00       ` Samuel Mize
1999-02-26  0:00         ` Don Harrison
1999-02-27  0:00           ` Nick Roberts
1999-03-01  0:00             ` Don Harrison
1999-03-01  0:00               ` Nick Roberts
1999-03-01  0:00                 ` Don Harrison
1999-03-02  0:00                   ` Matthew Heaney
1999-03-03  0:00                     ` Don Harrison
1999-03-03  0:00                       ` Samuel Mize
1999-03-04  0:00                         ` Don Harrison
1999-03-07  0:00                     ` Ehud Lamm
1999-03-01  0:00               ` Matthew Heaney
1999-03-01  0:00                 ` Nick Roberts
1999-03-03  0:00               ` Robert A Duff
1999-03-04  0:00                 ` Don Harrison
1999-03-04  0:00                   ` Robert A Duff
1999-03-01  0:00             ` Don Harrison
1999-03-02  0:00               ` Matthew Heaney
1999-02-28  0:00         ` Matthew Heaney
1999-03-01  0:00           ` Samuel Mize
1999-03-01  0:00           ` Nick Roberts
1999-03-01  0:00             ` Matthew Heaney
1999-03-02  0:00               ` Nick Roberts
1999-03-01  0:00             ` Matthew Heaney
1999-02-28  0:00       ` Matthew Heaney
1999-03-01  0:00       ` Tom Moran
1999-03-02  0:00         ` Matthew Heaney
1999-03-02  0:00           ` Tom Moran
1999-03-02  0:00             ` Matthew Heaney [this message]
1999-03-02  0:00               ` Tom Moran
1999-03-02  0:00                 ` Matthew Heaney
1999-03-02  0:00                   ` nabbasi
1999-03-02  0:00                     ` Matthew Heaney
1999-03-03  0:00                   ` Don Harrison
1999-03-03  0:00                     ` Single Extension; Polymorphic Arrays Nick Roberts
1999-03-03  0:00                       ` Nick Roberts
1999-03-08  0:00                         ` Matthew Heaney
1999-03-08  0:00                           ` Tucker Taft
     [not found]                             ` <m3ogm40wav.fsf@mheaney.ni.net>
1999-03-08  0:00                               ` Tucker Taft
1999-03-08  0:00                                 ` dennison
1999-03-09  0:00                                 ` Nick Roberts
1999-03-08  0:00                               ` Nick Roberts
1999-03-08  0:00                           ` Nick Roberts
1999-03-03  0:00               ` Can't export object of private type Don Harrison
1999-03-03  0:00                 ` Don Harrison
1999-03-03  0:00                   ` Nick Roberts
1999-03-04  0:00                     ` Don Harrison
1999-03-04  0:00                       ` Nick Roberts
1999-03-08  0:00                         ` Matthew Heaney
1999-03-09  0:00                         ` Don Harrison
1999-03-09  0:00                           ` Matthew Heaney
1999-03-09  0:00                             ` Nick Roberts
1999-03-10  0:00                             ` Don Harrison
1999-03-10  0:00                               ` Matthew Heaney
1999-03-04  0:00                       ` Nick Roberts
1999-03-04  0:00                         ` robert_dewar
1999-03-05  0:00                           ` Nick Roberts
1999-03-05  0:00                         ` Robert A Duff
1999-03-05  0:00                           ` Abstract Subprograms of Untagged Types Nick Roberts
1999-03-05  0:00                             ` Tucker Taft
1999-03-05  0:00                               ` Nick Roberts
1999-03-06  0:00                               ` robert_dewar
1999-03-05  0:00                             ` robert_dewar
1999-03-04  0:00                       ` Can't export object of private type fraser
1999-03-09  0:00                         ` Don Harrison
1999-03-08  0:00                     ` Matthew Heaney
1999-03-08  0:00                       ` Nick Roberts
1999-03-08  0:00                 ` Matthew Heaney
1999-03-10  0:00                   ` Don Harrison
1999-03-10  0:00                     ` Matthew Heaney
1999-03-10  0:00                       ` dennison
1999-03-10  0:00                         ` Robert A Duff
1999-03-10  0:00                           ` dennison
1999-03-11  0:00                             ` dennison
1999-03-10  0:00                           ` robert_dewar
1999-03-10  0:00                         ` robert_dewar
1999-03-10  0:00                           ` dennison
1999-03-10  0:00                             ` robert_dewar
1999-03-10  0:00                               ` dennison
1999-03-11  0:00                                 ` robert_dewar
1999-03-11  0:00                                   ` Don Harrison
1999-03-12  0:00                                     ` robert_dewar
1999-03-11  0:00                                 ` bill
1999-03-11  0:00                                   ` dennison
1999-03-11  0:00                                   ` Scott Ingram
1999-03-11  0:00                                     ` Larry Kilgallen
1999-03-12  0:00                                   ` dewar
1999-03-11  0:00                                 ` dennison
1999-03-11  0:00                           ` Don Harrison
1999-03-03  0:00           ` Don Harrison
1999-02-28  0:00     ` Matthew Heaney
1999-02-28  0:00   ` Matthew Heaney
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox