- Difference from anonymous inner types
Anonymous Type (or union):
- does not have a name and cannot be referenced by name
- may only appear nested within a named type or another anonymous type
- declares fields within the parent - either at separate memory locations (TYPE) or overlapping memory locations (UNION)
- cannot contain any static members or procedures declarations
- fields can be referenced
Code: Select all
type T
union
dim a as short
type
dim b1 as byte
dim b2 as byte
end type
end union
declare sub proc()
end type
sub T.proc()
b1 = 1
b2 = 2
print b1, b2, a
end sub
dim x as T
x.proc()
Named Type (or union):
- has a name that can be referenced to declare the data type for fields, variables, parameters, arrays, etc.
- can appear on it's own or nested inside another NamedType
- declaration of the type (or union) only
- does not declare any fields within the parent, so it does not add any size to the parent
Code: Select all
type T
union U
a as short
type '' anonymous
b1 as byte
b2 as byte
end type
declare sub proc()
end union
dim m as U
declare sub proc()
end type
sub T.proc()
m.b1 = 1
m.b2 = 2
print m.b1, m.b2, m.a
end sub
sub T.U.proc()
print b1, b2, a
end sub
dim x as T
x.proc()
x.m.proc()