tclitcl

How to pass itcl object from one class to another?


I have a 3 classes: A , B and C, theye are all in the same namespace: foo. I create an instance of the C inside A:

set object [::foo::C \#auto $param] 
$b addObject $object ;#  b is a instance of the B

But inside B I cannot use the object: It's said: invalid command name C0

How to create Itcl object and pass it from one class to another?


Solution

  • You need the fully-qualified name of the object in this case.

    $b addObject [namespace which $object]
    

    As long as B doesn't expect an unqualified name, that should work fine. (If B wants to recover the unqualified name, use namespace tail $fqn.)