Note: This command is equivalent to the command typevariable provided by the snit package in tcllib for approximately the same purpose. If used in a method defined directly on a class instance (e.g., through the oo::objdefine method definition) this is very much like just using:
namespace upvar [namespace current] $var $var
for each variable listed to classvariable.
oo::class create Counted {
initialise {
variable count 0
}
variable number
constructor {} {
classvariable count
set number [incr count]
}
method report {} {
classvariable count
puts "This is instance $number of $count"
}
}
set a [Counted new]
set b [Counted new]
$a report
→ This is instance 1 of 2
set c [Counted new]
$b report
→ This is instance 2 of 3
$c report
→ This is instance 3 of 3