Is it possible to "overload" based on visibility?

Steven Schveighoffer schveiguy at gmail.com
Wed Sep 23 19:27:13 UTC 2020


On 9/23/20 2:38 PM, 60rntogo wrote:
> So my questions are:
> 
> 1. Can I achieve my original goal of being able to refer to _x by one 
> name, so that I have read only access from outside the module and 
> read/write access from inside?

I would guess no. You have to use different names.

> 2. Is the behavior that allows me to call the private method intended? 
> This is such a blatant violation of encapsulation that it feels like a 
> bug either in the language or the implementation.

This is a bug in the language. Either varying ONLY by visibility of an 
overload should be disallowed, or you shouldn't have access to the 
private x. I don't know which one the answer is, but certainly the 
current behavior is erroneous.

-Steve


More information about the Digitalmars-d-learn mailing list