RosettaCodeData/Task/Create-an-object-at-a-given-address/FreeBASIC/create-an-object-at-a-given-address.basic
2023-07-01 13:44:08 -04:00

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