Constructor Qualifiers
Learn about constructor qualifiers in this lesson.
We'll cover the following...
Normally, the same constructor is used for mutable, const
, immutable
, and shared
objects:
Press + to interact
import std.stdio;struct S {this(int i) {writeln("Constructing an object"); }}void main() {auto m = S(1);const c = S(2);immutable i = S(3);shared s = S(4);}
Semantically, the objects that are constructed on the right-hand sides of those expressions are all mutable, but the variables have different type qualifiers. The same constructor is used for all of them. ...