34 lines
651 B
Text
34 lines
651 B
Text
' FB 1.05.0
|
|
|
|
Type Person
|
|
As String name
|
|
As Integer age
|
|
Declare Constructor(name As String, age As Integer)
|
|
End Type
|
|
|
|
Constructor Person(name As String, age As Integer)
|
|
This.name = name
|
|
This.age = age
|
|
End Constructor
|
|
|
|
Dim ap As Any Ptr = CAllocate(SizeOf(Person)) ' allocate memory to store a Person object
|
|
|
|
'create a Person object at the address of the memory we've just allocated
|
|
|
|
Dim p As Person Ptr = New(ap) Person("Teresa", 60)
|
|
|
|
'check addresses are same
|
|
Print ap, p
|
|
|
|
'check data is not corrupt
|
|
Print p -> name, p -> age
|
|
|
|
'call implicit destructor
|
|
p -> Destructor
|
|
|
|
'free memory
|
|
Deallocate(ap)
|
|
|
|
Print
|
|
Print "Press any key to quit"
|
|
Sleep
|