Adding a new design constraint to D

Tejas notrealemail at gmail.com
Tue Jun 14 15:17:42 UTC 2022


On Tuesday, 14 June 2022 at 12:35:24 UTC, bauss wrote:
> On Tuesday, 14 June 2022 at 12:19:40 UTC, Mike Parker wrote:
>> On Tuesday, 14 June 2022 at 10:50:56 UTC, bauss wrote:
>>
>>> No you really can't and I already proved that with a couple 
>>> examples in the other discussions on this topic; there are 
>>> situations where you cannot do that, such as accessing 
>>> private fields on a parent class using a sub class type 
>>> within the parent class' module.
>>
>> And Paul did show you how to do that with `child.Foo._c`.
>
> Not in a legal way.

It is literally part of the [language 
spec](https://dlang.org/spec/class.html#fields), how is it 
illegal?????

> Members of a base class can be accessed by prepending the name 
> of the base class  followed by a dot:

```d

class A { int a; int a2;}
class B : A { int a; }

void foo(B b)
{
     b.a = 3;   // accesses field B.a
     b.a2 = 4;  // accesses field A.a2
     b.A.a = 5; // accesses field A.a
}

```


More information about the Digitalmars-d mailing list