Re: How to hide type internals
- From: claude.simon@xxxxxxxxxxxxxxxxxx
- Date: 30 Jun 2006 04:19:11 -0700
Gerd a écrit :
Hi,
I would like to write a package that exports functions using a special
type, without showing the details in the spec (even not in the private
part).
In Modula-2 one can declare opaque types (which mostly are pointers but
also can be any type of word size).
Like this:
package keys is
type key;
function GetKey return key;
procedure FetchElement (k : key);
-- implementation of key not visible here
end keys;
package body keys
...
type Data is record
...
end record;
type key is access Data;
...
end keys;
package Keys is
type Key is private;
function Getkey return Key;
-- ...
private
type Imp_Key; -- deferred type to the body
type Key is access Imp_Key;
end Keys;
package body Keys is
type Imp_Key is new Integer; -- whatever type
function Getkey return Key
is
The_Key : Key := new Imp_Key;
begin
return The_Key;
end GetKey;
end Keys;
.
- References:
- How to hide type internals
- From: Gerd
- How to hide type internals
- Prev by Date: How to hide type internals
- Next by Date: Re: How to hide type internals
- Previous by thread: How to hide type internals
- Next by thread: Re: How to hide type internals
- Index(es):
Relevant Pages
|