ITCL - How to access associative array member inside a class?
How to access associative array member of a class inside the class itself? Itcl is modeled after C++, and in C++ we would write:
SomeObject.SomePublicMember = ...
How to do the same in Itcl? Without providing accessor procedure for such an array. I've seen that for usual plain variables this can be ob开发者_开发技巧tained by using cget:
$this cget -PublicMemberVariableName
However the following construct doesn't work:
$this cget -AssociativeArrayName(NamedIndex)
Is this possible at all?
Alas, cget won't get what you want. The array element isn't passed all the way down to ItclGetInstanceVar (I'm not sure why).
You can use get/set and the like:
class myObject {
public variable AssArray
constructor {} {
array set AssArray ""
}
method setArr { elem val } {
set AssArray($elem) $val
}
method getArr { elem } {
return $AssArray($elem)
}
method getFullArr {} {
return [array names AssArray]
}
精彩评论