• tcl OO - superclass variable is NOT exported

    From aotto1968@21:1/5 to All on Tue Aug 16 10:27:48 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rene@21:1/5 to aotto1...@gmail.com on Tue Aug 16 06:48:58 2022
    aotto1...@gmail.com 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)