April 19, 2024, 10:00:22 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


defining an Array of a Class question

Started by Guilect, October 20, 2008, 04:50:43 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Guilect

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.

Ionic Wind Support Team

October 20, 2008, 05:29:08 PM #1 Last Edit: October 20, 2008, 05:55:45 PM by Paul Turley
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

Ionic Wind Support Team