comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jrcarter@computer.org>
Subject: Re: Hiding a type
Date: Sun, 07 Jul 2002 01:58:10 GMT
Date: 2002-07-07T01:58:10+00:00	[thread overview]
Message-ID: <3D27A023.C483C92F@computer.org> (raw)
In-Reply-To: 3D275160.40907@hotmail.com

Ryan Tarpine wrote:
> 
> It looked correct when I wrote it, but that's not saying much since I
> only have a week of study under my belt :) GNAT tells me
> 
> test.ads:2:10: missing full declaration for private type "Public_Name"
> test.ads:8:13: "Public_Name" conflicts with declaration at line 2

You should pay attention to compiler messages. These are telling you 2
important things

1. There is no completion for the private type Public_Name
2. You cannot have a subtype with the same name as a type in the same
declarative region.

What you still seem to be missing, although you've been presented with
several examples doing it correctly, is that the completion ("full
declaration" in ARM-speak) of a private type is itself a type
declaration, not a subtype declaration:

package P is
   type T is limited private;
private -- P
   type T is new Integer;
end P;

There is no way in Ada to declare a type for which you cannot declare an
object. Limited private is good, since assignment is not defined for
limited types, and you might also want to add unknown discriminants to
the public view of the type:

type T (<>) is limited private;

Now the client cannot create a variable of the type, but can create a
constant by renaming a function call:

function F return T;
...
V : T renames F;

Another approach may be to use the package-as-object technique. In this
way of doing things, you would declare a generic package with only
subprograms exported. The data is declared in the body of the package.
Each instance of the package becomes an object with the subprograms
acting as the operations on that object.

-- 
Jeff Carter
"You cheesy lot of second-hand electric donkey-bottom biters."
Monty Python & the Holy Grail



  reply	other threads:[~2002-07-07  1:58 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-06 17:17 Hiding a type Ryan Tarpine
2002-07-06 21:30 ` Pat Rogers
2002-07-06 18:16   ` Ryan Tarpine
2002-07-06 22:49     ` sk
2002-07-06 22:52     ` Frank J. Lhota
2002-07-06 20:38       ` Ryan Tarpine
2002-07-07 10:31         ` Frank J. Lhota
2002-07-07 11:20       ` Simon Wright
2002-07-07 13:58         ` Frank J. Lhota
2002-07-07 22:24           ` Ryan Tarpine
2002-07-07 17:15         ` Jeffrey Carter
2002-07-07 17:58           ` Simon Wright
2002-07-06 23:10     ` chris.danx
2002-07-06 20:21       ` Ryan Tarpine
2002-07-07  1:58         ` Jeffrey Carter [this message]
2002-07-08  7:20         ` Preben Randhol
2002-07-06 23:12       ` chris.danx
replies disabled

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