Do constructors in D support the privacy keyword?

anonymous anonymous at example.com
Sat Sep 7 11:46:18 PDT 2013


On Saturday, 7 September 2013 at 18:37:11 UTC, Gary Willoughby
wrote:
> Do constructors in D support a privacy keyword? I'm guessing 
> not because if i declare one like this:
>
> class T
> {
>     private this()
>     {
>     }
> }
>
> i can still instantiate the class like this:
>
> auto x = new T();
>
> and there is no error thrown. Am i right in thinking the 
> privacy keyword is ignored?

In D, private symbols are accessible throughout their module. Try
instantiating the class from another module and you should get an
error.


More information about the Digitalmars-d-learn mailing list