Assignment Operator
Explore the assignment operator in D programming language, focusing on safe copying and destruction of objects during assignment. Understand how to define custom assignment operators, manage exceptions, and assign values from different types safely in structs.
We'll cover the following...
We'll cover the following...
What is an assignment operator?
Assingment is giving a new value to an existing object:
returnTripDuration = tripDuration; // assignment
The assignment is more complicated than the other special operations because it is actually a combination of two operations:
-
Destroying the left-hand side object
-
Copying the right-hand side object to the left-hand side object
However, applying those two steps in that order is risky because the original object would be destroyed before knowing that copying will ...