-
Book Overview & Buying
-
Table Of Contents
D Cookbook
By :
D structs are typically a value type (different variables are always different objects), as opposed to D's classes, which are always a reference type (different variables may refer to the same object). Sometimes, we want the struct that has reference semantics to ensure that assignment is cheap, for example.
To create a struct with reference semantics, we will execute the following steps:
Create a struct with a single data member that is itself a reference type, such as a pointer.
You may choose to use a private nested struct to hold the implementation, using alias this to forward methods automatically. The reference counted object in the previous chapter is a reference-type struct that uses this technique.
Use the struct normally—you should not use the ref storage class when passing it to functions.
Structs are a compile-time collection of their contents. If a struct has only one member, it works almost exactly the same way...
Change the font size
Change margin width
Change background colour