[email protected] schrieb am Dienstag, 16. August 2022 um 10:27:52 UTC+2:
Hi,
easy OO example
__________________________________________
oo::class create A {
variable aa
constructor {} {
set aa 1
}
method printA {} { puts $aa }
}
oo::class create B {
superclass A
method printB {} { puts $aa }
}
B create test
test printA
test printB
__________________________________________
create an *unexpected* result
__________________________________________
1
can't read "aa": no such variable
while executing
"puts $aa "
(class "::B" method "printB" line 1)
invoked from within
"test printB"
(file "test.tcl" line 18)
Shell beendet 1
__________________________________________
the automatic *variable* aa in "A" is *NOT* visible in "B"
→ why?
mfg
You need to define your variable also in the new class like:
oo::class create B {
superclass A
variable aa
method printB {} { puts $aa }
}
HTH
Rene
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)