www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - private declaration in module

reply novice <novice_member pathlink.com> writes:
Hello. Can you help me? Newbie question:
how i can hide come functions and other declarations in my D module from import?

I want declare one or more public function in module (so other modules can use
it), and one or more private (local) functions (for internal usage only, so
other modules can't use it directly).

Thanks.

Alex
Sep 22 2004
next sibling parent Sjoerd van Leent <svanleent wanadoo.nl> writes:
novice wrote:
 Hello. Can you help me? Newbie question:
 how i can hide come functions and other declarations in my D module from
import?
 
 I want declare one or more public function in module (so other modules can use
 it), and one or more private (local) functions (for internal usage only, so
 other modules can't use it directly).
 
 Thanks.
 
 Alex
Very simple, all protection attributes are module based (within a class, a struct, a template or without) with the exception to protected. package = The module and submodules may access it private = Only the module may access it protected = Only within classes and interfaces, only subclasses may access it public = Every module may access it Also: import = Imported modules are visible to other modules using your module private import = Imported modules are hidden for other modules using your module Regards, Sjoerd
Sep 22 2004
prev sibling parent reply Bastiaan Veelo <Bastiaan.N.Veelo ntnu.no> writes:
novice wrote:
 Hello. Can you help me? Newbie question:
 how i can hide come functions and other declarations in my D module from
import?
 
 I want declare one or more public function in module (so other modules can use
 it), and one or more private (local) functions (for internal usage only, so
 other modules can't use it directly).
 
 Thanks.
 
 Alex
See protection attributes in http://www.digitalmars.com/d/attribute.html. #module mypackage.mymodule; #package { #private { You're welcome, Bastiaan.
Sep 22 2004
parent reply novice <novice_member pathlink.com> writes:
Thanks to Sjoerd and Bastiaan!

May be, my question cause is my bad english. At
http://www.digitalmars.com/d/attribute.html
"private" described as applied to "enclosed class" only,
but my program has no classes.

Private means that only members of the enclosing class can access the member,
or members and functions in the same module as the enclosing class. Private
members cannot be overridden. Private module members are equivalent to static
declarations in C programs
Sep 22 2004
next sibling parent Andy Friesen <andy ikagames.com> writes:
novice wrote:
 Thanks to Sjoerd and Bastiaan!
 
 May be, my question cause is my bad english. At
 http://www.digitalmars.com/d/attribute.html
 "private" described as applied to "enclosed class" only,
 but my program has no classes.
Private can be used at the module level too. module foo; private int helper() { ... } int somethingInteresting() { ... } -- andy
Sep 22 2004
prev sibling parent reply Bastiaan Veelo <Bastiaan.N.Veelo ntnu.no> writes:
novice wrote:
 Thanks to Sjoerd and Bastiaan!
 
 May be, my question cause is my bad english. At
 http://www.digitalmars.com/d/attribute.html
 "private" described as applied to "enclosed class" only,
 but my program has no classes.
 
 
Private means that only members of the enclosing class can access the member,
or members and functions in the same module as the enclosing class. Private
members cannot be overridden. Private module members are equivalent to static
declarations in C programs
It is not your english, that sentence is misleading. I think "enclosing class" should read something like "enclosing class, enclosing template or enclosing module, whatever comes first". Bastiaan.
Sep 22 2004
parent "Ben Hinkle" <bhinkle mathworks.com> writes:
"Bastiaan Veelo" <Bastiaan.N.Veelo ntnu.no> wrote in message
news:cis370$2jgu$1 digitaldaemon.com...
 novice wrote:
 Thanks to Sjoerd and Bastiaan!

 May be, my question cause is my bad english. At
 http://www.digitalmars.com/d/attribute.html
 "private" described as applied to "enclosed class" only,
 but my program has no classes.


Private means that only members of the enclosing class can access the
member,
or members and functions in the same module as the enclosing class.
Private
members cannot be overridden. Private module members are equivalent to
static
declarations in C programs
It is not your english, that sentence is misleading. I think "enclosing class" should read something like "enclosing class, enclosing template or enclosing module, whatever comes first". Bastiaan.
Some word-smithing wouldn't hurt, but note it does say "Private module members are equivalent to static ..." so it does address what private means for module-level declarations.
Sep 22 2004