- 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) {} alias function myfunction;
myfunction(x);
|
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); function(z);
|
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 { Monday,
Thuesday,
Wednesday
}
printf("%d", Day.Monday); printf("%d", Day.Thuesday); 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 }
|
|