Copying and Assignment
Explore the concepts of copying and assignment in D classes. Understand how class variables reference objects, the role of dup() for creating copies, and how assignment impacts references and garbage collection in D.
We'll cover the following...
We'll cover the following...
Copying
Copying affects only the variables, not the object.
Because classes are reference types, defining a new class variable as a copy of another makes two variables that provide access to the same object. The actual object is not copied.
Since no object gets copied, the postblit function this(this) is not available for classes.
auto variable2 = variable1;
In the code above, variable2 is being initialized by variable1 and the two variables start ...