Class 如何继承多次继承基类的类
标题不清楚。我在这里解释 我有一个软件包说Class 如何继承多次继承基类的类,class,tcl,itcl,Class,Tcl,Itcl,标题不清楚。我在这里解释 我有一个软件包说软件包提供测试。它有类。我正在使用Itcl。包具有以下结构 ::itcl::class classA { written something having constructor and methods } ::itcl::class classB { inherit ::test::classA having its own constructor and methods } ::itcl::class classC { inherit ::tes
软件包提供测试
。它有类
。我正在使用Itcl
。包具有以下结构
::itcl::class classA {
written something having constructor and methods
}
::itcl::class classB {
inherit ::test::classA
having its own constructor and methods
}
::itcl::class classC {
inherit ::test::classA
having its own constructor and methods
}
::itcl::class classD {
inehrit ::test::classB ::test::classC
having its own constructor and methods
}
当我需要软件包测试时,我得到以下错误信息
class "::test::classD" inherits base class "::test::classA" more than once:
如何处理错误由于路径不明确,不允许菱形继承。
即
作为解决方法,您可以使用组合(has-a)而不是继承
(is-a)
现在在classD中,您必须指定代码到达基的classB或classC路径。您可以尝试切换到TclOO,它允许这种类结构。@DonalFellows:因为我的框架使用的是itcl
。我无法切换到TclOO
TopClass
/ \
LeftClass RightClass
\ /
BottomClass
::itcl::class classA {
}
::itcl::class classB {
inherit ::test::classA
}
::itcl::class classC {
inherit ::test::classA
}
::itcl::class classD {
constructor {} {
set _b [::test::classB #auto]
set _c [::test::classC #auto]
}
destructor {
::itcl::delete $_b
::itcl::delete $_c
}
private {
variable _b ""
variable _c ""
}
}