User-defined type variable usage

To access a member of a variable of a user-defined type (UDT variable), use this syntax:

 

var.member

 

Here var is name of the variable of user-defined type, member is member's name. This syntax also is used when var is pointer.

 

To access the member of a single-member UDT variable, can by used only var. Exception is OLE Automation types.

 

User-defined types can contain other user-defined types. Assume that variable a has member b, and b has member c. To access c use a.b.c. If b is base of a, c can be accessed using syntax a.c.

 

From a member function, members of variable for which the function is called can be accessed directly or using syntax this.member. Here this is special variable that can be used only in member functions.

 

UDT variables often are quite large. To avoid copying of whole variable when passing it to a function, functions usually accept pointer or reference. To pass a variable to a function that expects pointer, prepend the address-of operator &.

 

Examples

 Declare variable of type RECT (RECT is defined as type RECT left top right bottom):
RECT r
 Use members:
r.left = 100
r.right = r.left + 180
 Copy r to rr:
RECT rr=r
 Pass address of r to function:
GetWindowRect(win("Quick") &r)
 Define type MY:
type MY word'w RECT'r byte'arr[32]
 Declare variable m of type MY and use members:
MY m
m.r.left = 100
int i = m.arr[4]
lpstr s=&m.arr; out s
 Pointers, references:
MY* mp = &m
i = mp.r.top
MY& mr = &m
i = mr.r.top