Why do private member variables behaved like protected in the same module when creating deriving class?

FeepingCreature feepingcreature at gmail.com
Mon Oct 29 08:34:39 UTC 2018


On Monday, 29 October 2018 at 05:13:22 UTC, unprotected-entity 
wrote:
> On Sunday, 28 October 2018 at 11:32:07 UTC, Mike Parker wrote:
>>
>> In D, the module is the unit of encapsulation, not the class.
>
> That is not entirely correct.
>
> ---
> module test;
> import std.stdio;
> void test() { int a; }
> void main() { writeln(a); } // Error: undefined identifier 'a'
> ---
>
> The D module still considers a function to be it's own unit of 
> encapsulation.
>
> Classes no longer have that status in D.
>
Yes they do.
---
module test;
import std.stdio;
class C { int a; }
void main() { writeln(a); } // Error: undefined identifier 'a'


More information about the Digitalmars-d mailing list