Inheritance of a static function in [incr Tcl]

Inheritance in incr Tcl does not work properly. Consider the code below.

package require Itcl

::itcl::class Base \
{
public {
    proc function { } { puts "==== Base::function" }
}
}

::itcl::class Derived { inherit Base }

Base::function
Derived::function    ;# FAILS

The last line fails, so Base::functionit is not inherited in Derived, although it Derivedinherits from Base.

Am I doing something wrong or is incr Tcl designed to behave like this?

+3
source share
2 answers

Reading documents I do not think that the procs in the itcl class work the way you think they should:

proc? args?? ?      . - . , proc . proc , .      args, . body proc, args .      proc proc , . , proc "className:: proc". Procs , , .

, proc , , . , :

package require Itcl

::itcl::class Base {
    public {
        proc function { } { puts "==== Base::function" }
    }
}

::itcl::class Derived { 
inherit Base 
    public {

        proc function { } { 
            puts "==== Derived::function"
            return [Base::function] 
        }
    }
}

Base::function
Derived::function    ;# FAILS
+3

, Base::function, ( ) proc Base. Itcl, , procs. proc function Base, proc.

itcl::class Base {
  public {
    proc function { } { puts "==== Base::function" }
  }
  public method test {} {
    $this function
  }
  public method test2 {} {
    function
  }
}

Base bb
bb test   ;# yields error: bad option "function"
bb test2  ;# works as expected
+1

Source: https://habr.com/ru/post/1786863/


All Articles