@erin j Is there a way to have a default value for a custom class similar to what xojo primitives do? Like an implicit default constructor?
For example, lets say myCustomClass is a wrapper for integer and has operator_add, _addRight and _convert(value as integer) implemented.
dim mcc as myCustomClass
dim ii as integer = 14 + mcc
Is there a way to get the code above to work without a nilobjexception and without explicitly stating that mcc is new myCustomClass = 0?
A usage would be to have these as properties of other classes that do not need to be explicitly instantiated to a default value.
You can do *some* of what you asked.
Operator Convert has 2 forms
operator_convert() as TYPE - this is the "convert to" operator that is often implemented on classes
and there is operator_convert(t as type) - this is the "convert from" form.
And once you have the "convert from" form then you could write:
dim c as currency
dim u as usdollar
u = c
and the last line invokes the "convert from" form, and a new us dollar instance is created from the currency.
Some things to note though - since the operator_convert from style does NOT call the constructor IF there is a requirement that it be called then you should do that in the operator_convert. Here’s an example project: