Previous Topic Next topic Print topic


ValueTypes

Value types can contain data members and function members, similar to classes. The difference is that value types store the data as values and don't require heap allocation.

valuetype-specification

valuetype-header constraints-paragraph static-or-instance-field static-or-instance-member

valuetype-header

access-modifier type-specifier attribute-clause

Example

valuetype-id StudentRecord.
01 aName string public.
01 gpa float-short public.
method-id new.
procedure division using by value nam as string, 
                                  gpa as float-short.
    set aName to nam
    set self::"gpa" to gpa
end method.
end valuetype.
 
class-id a.
method-id main static.
local-storage section.
01 stu type StudentRecord value new StudentRecord("Bob", 3.5).
01 stu2 type StudentRecord.
procedure division.
    set stu2 to stu
    set stu2::aName to "Sue"
    display stu::aName   *> Prints Bob
    display stu2::aName  *> Prints Sue
end method.
end class.
Previous Topic Next topic Print topic