Why is D unpopular

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Mon Jun 13 14:15:15 UTC 2022


On Monday, 13 June 2022 at 13:51:40 UTC, Paul Backus wrote:
> This is necessary because D allows you to define fields with 
> the same name in a base class and its derived class;

Hardly necessary, C++ will error on this:
```c++
class A {
     int x=1;
     friend int main();
};

class B  : public  A {
     int x=4;
};


int main()
{
     B obj{};
     cout << obj.x;
}
```
But allow this:
```c++
class A {
     int x=1;
     friend int main();
};

class B  : public  A {
     int y=4;
};


int main()
{
     B obj{};
     cout << obj.x;
}
```

Of course, since C++ has multiple inheritance it has to deal with 
conflicts. D forbid it, although I guess you could argue that the 
subclass should not be affected by naming of fields in the 
superclass.

I still prefer that this is not allowed as shadowing in class 
hierarchies makes debugging so much more confusing.





More information about the Digitalmars-d mailing list