【问题标题】:Is there a way to make [incr Tcl] classes friends?有没有办法让 [incr Tcl] 类成为朋友?
【发布时间】:2011-01-21 18:32:15
【问题描述】:

有没有办法在incr Tcl中获得班级之间的友谊?

考虑下面的代码。

package require Itcl

::itcl::class A {
   private {
      proc f { } {
         puts "==== A::f"
      }
   }
}

::itcl::class B {
   public {
      proc g { } {
         puts "==== want to be able to call A::f"
      }
   }
}

我希望A::fA bur 函数B 之外不可见。我怎样才能做到这一点?

【问题讨论】:

    标签: oop tcl private friend incr-tcl


    【解决方案1】:

    Itcl 不提供好友。

    您可以通过使用namespace inscope 构造调用来解决此问题,如下所示:

    namespace inscope A {A::f}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 2012-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多