Structs - Vala Reference Manual

## 13. Structs

A struct is a data type that can contain fields, constants, and methods.

The simplest struct declaration looks like this:

    struct StructName {
            int some_field;
    }

A struct must have at least one field, except in either one of the following cases:

- It's external

- It has either one of `[BooleanType]`, `[IntegerType]` or `[FloatingType]` attributes

- It inherits from another struct

### 13.1 Struct declaration

> struct-declaration: [ access-modifier ] struct qualified-struct-name [ : super-struct ] { [ struct-members ] } qualified-struct-name: [ qualified-namespace-name . ] struct-name struct-name: identifier struct-members: struct-member [ struct-members ] struct-member: struct-creation-method-declaration: struct-field-declaration struct-constant-declaration struct-method-declaration

If a super-struct is given, the struct-name becomes an alias for that struct.

### 13.2 Controlling instantiation

> struct-creation-method-declaration: [ struct-access-modifier ] struct-name [ . creation-method-name ] ( param-list ){ statement-list } struct-name: identifier

Unlike in a class, any code can go in this method.

### 13.3 Struct fields

Documentation

> struct-field-declaration: [ access-modifier ] [struct-field-type-modifier] qualified-type-name field-name [ = expression ] ; struct-field-type-modifier: static

### 13.4 Struct constants

> class-constant-declaration: [ class-access-modifier ] const qualified-type-name constant-name = expression ;

### 13.5 Struct methods

See Methods, See Classes/Class methods

> struct-method-declaration: [ access-modifier ] [ struct-method-type-modifier ] return-type method-name ( [ params-list ] ) method-contracts [ throws exception-list ] { statement-list } struct-method-type-modifier: static

### 13.6 Examples

Demonstrating...

    // ...