Reference Types
Explore how reference types work in D programming. Learn the key differences between reference variables and reference types, how slices, class objects, and associative arrays behave as references, and how assignment affects them. Understand concepts like identity, aliasing, and null references to build a solid foundation in managing reference types.
Variables of reference types have individual identities, but they do not have individual values. They provide access to existing variables.
Slices as reference types
We have already seen this concept with slices. Slices do not own elements, they provide access to existing elements:
Contrary to reference variables, reference types are not simply aliases. To see this distinction, let’s define another slice as a copy of one of the existing slices:
int[] slice2 = slice;
The two slices have their own addresses. In other words, they have separate identities:
The following list is a summary of the differences between reference variables and reference ...