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

Mike Parker aldacron at gmail.com
Sun Oct 28 05:28:31 UTC 2018


On Sunday, 28 October 2018 at 04:38:53 UTC, unprotected-entity 
wrote:

> oh... so you accidently typed b.x++ in main().. or someother 
> code outside of the class), instead of b.increment() 
> ...well...to bad.
>

You can make the same mistake inside the class:

class Foo {
    private int x;
    void increment() {...}
    ...
    void doSomethingInternal() { x++; }
}

How is making that mistake outside of that final curly brace any 
different or any worse? It's all in the same file.


More information about the Digitalmars-d mailing list