...

/

Definition of Structs

Definition of Structs

Learn about structs, how they are defined and accessed in D.

Chapter overview

Fundamental types are not suitable to represent higher-level concepts. For example, although a value of type int is suitable to represent the hour of the day, two int variables would be more suitable together to represent a point in time: one for the hour and the other for the minute.

Structs are the features that allow defining new types by combining already existing types. The new type is defined by the struct keyword. By this definition, structs are user-defined types. Most of the content of this chapter is directly applicable to classes as well, especially the concept of combining existing types to define a new type.

This chapter covers only the basic features of structs. You will see more of structs in the following lessons: