September 12, 2011 Re: How do I create a module-local immutable class object? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On Sat, 10 Sep 2011 17:06:44 -0400, Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:
> On 9/10/11, bearophile <bearophileHUGS@lycos.com> wrote:
>> Andrej Mitrovic Wrote:
>>
>>> Wait a minute, I've just realized private on a class definition has no
>>> effect. Why is that?
>>
>> Try to import that class from another module...
>
> It doesn't stop imports, that's what I'm saying. I can import and
> instantiate the class from another module even though it's a private
> class definition.
For a long time, protection attributes have no effect on a global scope. I personally think they should either work (only private/package/public) or be a compiler error. To silently be accepted is really confusing.
However, on an inner scope, you can declare a private class/struct:
a.d:
class C
{
private struct S
{
}
}
main.d:
import a;
void main()
{
C.S s; // error
}
-Steve
|
Copyright © 1999-2021 by the D Language Foundation