my_basic icon indicating copy to clipboard operation
my_basic copied to clipboard

Class member variable default value issue

Open blazer2k1 opened this issue 2 years ago • 0 comments

As demonstrated in the below sample:

class foo
	var a = 1
	def inc()
		a = a + 1
	enddef
Endclass

class bar(foo)
    var class = "test"
Endclass

boo = new(foo)
boo.inc() ; incrementing boo.a also increments zap.a?

zap = new(bar)
; zap.a = 1
; have to initialize zap.a to not increment issue above, 
; but what is the point of having class variable default values?

; boo.inc() ; putting the call here also seems to not increment zap.a

zobj = reflect(zap)
loop = iterator(zobj)

While move_next(loop)
    name = get(loop)
    value = zobj(name)
    Print name, " = ", value
Wend

outputs

CLASS = test
A = 2 ; should be 1 since boo.inc() is called, not zap.inc()
...
...

blazer2k1 avatar Sep 20 '23 10:09 blazer2k1