What is the correct way to define an array of a Class?
I tried the following (compile as console) :
Class foobar
def m_x as int
declare foobar()
declare setx(value as int)
declare getx(), int
ENDCLASS
sub foobar::foobar()
m_x = 99
ENDSUB
sub foobar::setx(value as int)
m_x = value
ENDSUB
sub foobar::getx(),INT
return m_x
ENDSUB
' Test code for above Class
def test[3] as foobar
print test[0].getx()
print test[1].getx()
print test[2].getx()
DO:UNTIL INKEY$ <> ""
But the output is :
99
0
0
and I have checked to see that the Class constructor sub routine is only being called one time.
Thanks in advance for any help.
It is a limitation of the language. The constructor is only called for the first element of an array.
You can call it yourself for the other elements.
for x = 1 to n
test[ x ].foobar()
next x
OK.
Thanks.