D Documentation  
User Defined Types
  • alias
  • typedef
  • enum
  • struct
  • union
  • class

Alias
An alias is simply an extra name for a type. It does not matter what kind of a type it is, buildin or user.

An alias may also be an alias for a function or namespace.

alias int thisisint;
thisisint x = 5;
int function(int u) {}
int function(thisisint) {} // error; conflicts with int version of function
alias function myfunction;
myfunction(x); // this will call 'function'


This will just create an int with value 5. 'thisisint' will be fully treated as an int; when doing overloading one must take care of this. If you want it to behave as though it's it's own type instead of a copy reference, you must use typedef.

Typedef
A typedef is almost the same as an alias, though it may not be used to regroup/label functions or namespaces. Typedefs will act as though it's it's own type, so if you do

typedef int myint;
void function(int x) { }
void function(myint x) { }
myint i = 4;
int z = 5;
function(i); // the 'myint' version will be called
function(z); // the int version will be called


Enum
An enum is an emuration of constants. An enum may be derived from a basic type to assign to it a size in bytes (equal to the type derived). Enums are useful when creating certain properties.

enum Day : int { // where int is derived type, may be left out
  Monday,
  Thuesday,
  Wednesday
}
printf("%d", Day.Monday); // will print 0
printf("%d", Day.Thuesday); // will print 1]
Day myDay = Day.Monday;


Usually everytime you add an element, the element value is increased by one. You may also be explicit about the constant value assigned to an element:

enum Day {
  Monday = 10,
  Thuesday // will be 11
}
Created using PHP docwiki written by Markus Dangl. Best viewed with Mozilla Firefox.