...

/

Definition, Construction, and Destruction

Definition, Construction, and Destruction

Get to learn about the definition, construction, and destruction of class objects.

We'll cover the following...

Definition

Classes are defined by the class keyword instead of the struct keyword:

class ChessPiece {
    // ...
}

Construction

As with structs, the name of the constructor is this. Unlike structs, class objects cannot be constructed by the { } syntax.

Press + to interact
class ChessPiece {
dchar shape;
this(dchar shape) {
this.shape = shape;
}
}
void main() {
}

Unlike structs, there is no automatic object construction where the constructor parameters are ...