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

Stanislav Blinov stanislav.blinov at gmail.com
Fri Oct 26 18:45:32 UTC 2018


On Friday, 26 October 2018 at 18:16:38 UTC, 12345swordy wrote:
> Mike Parker told me that this is intentional and not a bug.

It's not a bug.

> However according to the spec: "Symbols with private visibility 
> can only be accessed from within the same module. Private 
> member functions are implicitly final and cannot be overridden."

Why "however"? There's no contradiction. Within a module, you 
have access to everything.

> Why private member variables behave like protected member 
> variables in the same module?

Because according to the spec, "Symbols with private visibility 
can only be accessed from within the same module."

It's *your* module. You already have access to it's 
implementation in it's entirety. There's absolutely no need for 
artificial restrictions. To keep your desk drawer tidy you, well, 
keep it tidy, not mess it up and throw away the key.

> Can you explain your thought process when it comes to this 
> design decision Walter Bright?

I'm sure Walter should be honored to be graced with such an 
eloquent inquiry.

> Is there no way to mark the private member variables as "final" 
> in the same module?

No.


More information about the Digitalmars-d mailing list