Classes are design reference types. They should not be transmitted by value. Similarly with Java and C #. However, unlike Java and C #, D also has full-fledged user-defined value types, since it has structures (C # also has structures, but they are much more limited). The fact that C ++ combines the two causes problems like splitting objects .
Now, obviously, there are times when you want to copy a reference type. The solution to this is cloning . You give your class the clone function, which returns a copy of the object it called. This way you can copy it when you need it, and only copy it when you need it. Java and C # have a standard clone function that is implemented by most types, but for some reason D is not. I do not know why. But still, it's easy enough to declare such a function yourself for your own types. It just won't be on Object , which allows you to use it for almost any class object, without worrying about what the actual type is, as you can do in Java and C #. You can always create a copy constructor if you want, but less flexible because you need to know the type of the object being copied, whereas with clone it can be any type that is derived from the type clone returns (which will be Object in the case of Java and C #, but will be what you decide in D, since the function is non-standard).
Jonathan m davis
source share