"constructor args ?init? body"

  class child {

      public variable parent_a "";
      public variable parent_b "";
      public variable child_a

      # pass arguments in an init code fragment
      constructor { args } {
          puts stdout "parent this -$this- args -$args-"
          eval configure $args
          # check value of parent_a
          if { $parent_a == "" } {
              puts "--> bad parent_a"
          }
      } {
          puts stdout "child this -$this- args -$args-"
          eval configure $args
      }
 
  }

  child testobj \
      -child_a "val_child_a" \
      -parent_a "val_parent_a"

posted @ 2011-08-05 17:28  greencolor  阅读(183)  评论(0编辑  收藏  举报