Search⌘ K

Member Access and Member Functions

We will discuss member access and member functions in this lesson.

Member access

Like structs, the members are accessed by the dot operator:

D
import std.stdio;
class ChessPiece {
dchar shape;
this(dchar shape) {
this.shape = shape;
}
}
void main() {
auto king = new ChessPiece('♔');
writeln(king.shape);
}

Although the syntax makes it look as if a member of the variable is being accessed, it is actually a member of the object. Class variables do not have members, the class objects do. The king variable does not have a shape member, the anonymous object ...