Constructor Parameter vs Member Variable
DrDread
DrDread at cheese.com
Tue Dec 5 17:45:27 UTC 2023
On Tuesday, 5 December 2023 at 16:30:42 UTC, Jonathan M Davis
wrote:
> On Tuesday, December 5, 2023 7:23:26 AM MST Christopher Winter
> via Digitalmars-d wrote:
>> [...]
>
> A big difference is that if you shadow a local variable with
> another local variable, you don't have any way to differentiate
> between them. So, when you shadow a local variable, that
> variable becomes inaccessible within that section of code,
> whereas with a member variable, you can distinguish with the
> this reference, and with a variable at module scope, you can
> differentiate a leading dot. So, the error prevents you from
> making variables inaccessible, whereas there is no need for
> such an error when shadowing non-local variables.
>
> [...]
a better option would be to force the use of this. to access
member variables instead of implicitly making them part of the
scope. but that ship has sailed a long time ago
More information about the Digitalmars-d
mailing list