[incr Tcl] 中的静态函数继承
incr Tcl 中的继承无法按预期工作。考虑下面的代码。
package require Itcl
::itcl::class Base \
{
public {
proc function { } { puts "==== Base::function" }
}
}
::itcl::class Derived { inherit Base }
Base::function
Derived::function ;# FAILS
最后一行失败,因此 Base::function
不会在 Derived
处继承,尽管 Derived
继承自 Base
。
我做错了什么吗,还是 incr Tcl 的设计行为所以?
Inheritance in incr Tcl doesn't work as expected. 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::function
is not inherited at Derived
, though Derived
inherits from Base
.
Am I doing something wrong, or incr Tcl is designed to behave so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
阅读文档我不认为 itcl 类中的过程按照您认为应该的方式工作:
我对此的理解是,过程与其类相关联,可以在派生类中引用它,但没有在其中定义。例如以下作品:
Reading the docs I don't think that procs in an itcl class work the way you think they ought to:
My reading of this is that the proc is associated with it's class, it can be referred to in the derived class but it isn't defined in it. For example the following works:
您定义的
Base::function
过程(或多或少)是命名空间Base
中的常规过程。当你在 Itcl 中继承时,你只是继承方法,而不是继承过程。在相关注释中,您不能从Base
的实例调用 procfunction
,您必须像调用任何常规 proc 一样调用它。The proc you defined
Base::function
is (more or less) a regular proc in the namespaceBase
. When you inherit in Itcl, you just inherit methods, you don't inherit procs. In a related note, you cannot call the procfunction
from an instance ofBase
, you have to call it like any regular proc.