3 ms·
.. you forgot to mention also, that (in the context of a D module) D stops treating a user-defined class-type as real type. Additionally, a D class is a referen
by SilentLambda 4y ago
.. you forgot to mention also, that (in the context of a D module) D stops treating a user-defined class-type as real type. Additionally, a D class is a reference type. Whereas in C++, a class type is a real type (treated as any built-in type), and is a value type (by default).
Nor does D have a concept of C++ friend.
So even when it comes to classes, C++ and D are miles apart.
- WalterBright 4y agoD structs are value types, D classes are reference types. This was done to avoid mistakes like having a type that is sometimes used as a value type and sometimes as a reference type.
- SilentLambda 4y ago..and in the context of a module.. not even used as a type at all.
- SilentLambda 4y agoWould have been much better in my opinion, if D had maintained a C like struct (not a C++ like struct), and a C++ like class. That would have solved the problem you identified, while still allowing for the class to be what it was designed to be. The mistake C++ made was the mistake you identified. But the solution you provided in D is its own mistake.
- WalterBright 4y agoThe C++ class would require the user to constantly remember it has to be passed by reference, not by value. D making the class a reference type means the user cannot mix them up. It has worked well from the beginning, it is not a mistake.