0

标题不清楚。这里我解释

我有一个包裹说package provide test。它有classes. 我正在使用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
}

当我需要时package test,我得到以下错误

class "::test::classD" inherits base class "::test::classA" more than once:

我该如何处理错误

4

1 回答 1

1

由于路径不明确,不允许使用菱形继承。IE

      TopClass
      /       \
LeftClass   RightClass
      \       /
     BottomClass

作为解决方法,您可以使用组合 (has-a) 而不是继承 (is-a)。

::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 ""
   }
}

现在在 classD 中,您必须特定于代码到达基础的 classB 或 classC 路径。

于 2014-04-16T10:11:05.847 回答