Constructors & Destructors¶
Classes in CrossBasic support:
- Constructor overloads via
Sub Constructor(...). - Resource cleanup via built-in
Close(akaDestroy) methods.
Constructors¶
Define one or more Sub Constructor blocks in your class:
Class Pair
Sub Constructor() // default
End Sub
Sub Constructor(left As Variant, right As Variant) // overloaded
Self.LeftValue = left
Self.RightValue = right
End Sub
End Class
When you New Pair(...), the appropriate constructor is selected by matching parameter count and types .
Destructors / Cleanup¶
- Built-in classes often provide a
DestroyClose()method to free native resources. - Call
Close()when you’re done with a resource to free its memory immediately. ARC will handle them otherwise:
- User-defined classes can implement a
Sub Destructor()if necessary; it will be called automatically when the instance is collected.