Oxygen Basic
Programming => Bugs & Feature Requests => Topic started by: Brian Alvarez on July 25, 2019, 07:21:29 PM
-
Hello Charles, i would like to create a static class (or a global class that is initialized AFTER its definition).
class THECLASS
method constructor(int a)
end method
end class
FUNCTION THESUB(byref THECLASS *v) AS INT
' nothing
END FUNCTION
' This works fine.
NEW THECLASS a(1)
THESUB(a)
' This raises compile-time error.
NEW STATIC THECLASS a2(2)
THESUB(a2)
The Static portion reports:
ERROR: ERROR: nesting error `endif` (no beginning)
WORD: endif
LINE: 209
FILE: "main source
It almost works if i do this:
dim static THECLASS a2 : a2.constructor(2)
THESUB(a2)
I can use the class a2 as normal... but then THESUB doesnt recognize it's datatype and rejects it as a parameter...
ERROR: ERROR: parameters mismatch for procedure thesub
params given : #theclass@1
OPTIONS:
thesub(theclass) returns int
WORD: a3
LINE: 210
FILE: "main source
-
Hi Brian,
A static class is much the same as a UDT:
The constructer and destructor can be invoked explicitly any time.
static THECLASS a2
class THECLASS
method constructor(int a)
end method
end class
FUNCTION THESUB(THECLASS *v) AS INT
' nothing
END FUNCTION
' This works fine.
NEW THECLASS a(1)
THESUB(a)
...
DEL a
static THECLASS a2
'THECLASS a2
'dim a2 asTHECLASS
a2.constructor(2)
THESUB(a2)
-
Thanks Charles... the problem was that it doesnt work with explicit byref...
if no explicit byref and no explicit byval, what is the difference?
-
byref and byval are generally not used in C-style headers. (byval would be the default).
fun(byref myClass*a) would be the equivalent of fun(myClass**a)
byref is the default for Basic-style headers, as in PowerBasic
-
Got it. Thanks Charles.