comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Woodcraft <mattheww@chiark.greenend.org.uk>
Subject: Using renaming declarations to make private subprograms visible
Date: 25 Aug 2001 14:13:40 +0100
Date: 2001-08-25T14:13:40+01:00	[thread overview]
Message-ID: <87itfcnuyj.fsf@chiark.greenend.org.uk> (raw)


Suppose I want a private type that I can convert to a string and back:


package Foo is

   type Token_Type is private;

   function To_Token (Source : String) return Token_Type;

   function To_String (Source : Token_Type) return String;

   [...]

private

   [...]	

end Foo;



Now suppose that (for the moment), I want to implement this type using
an unbounded string. I can make Token_Type a derived type of
Unbounded_String, and use renaming declarations to make some of the
'inherited' subprograms publicly visible:

private

   type Token_Type is new Ada.Strings.Unbounded.Unbounded_String;

   function To_Token (Source : String) return Token_Type
     renames To_Unbounded_String;

    -- No good
   function To_String (Source : Token_Type) return String
     renames To_String;

   [...]


The trouble is, this doesn't work when I want the public name of a
subprogram to be the same as the private name (eg, To_String above), as
my new definition overrides the inherited one, and I end up trying
renaming the function to itself.

Is there any way to make the inherited subprogram publicly visible with
the same name? Or am I better off making Token_Type a record with one
component, rather than a derived type?


-M-



             reply	other threads:[~2001-08-25 13:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-25 13:13 Matthew Woodcraft [this message]
2001-08-25 18:27 ` Using renaming declarations to make private subprograms visible Jeffrey Carter
2001-08-26 10:59   ` Matthew Woodcraft
2001-08-26 12:29     ` Marc A. Criley
2001-08-27  5:31     ` Jeffrey Carter
replies disabled

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