## Tcl9.0.3/Tk9.0.3 Documentation > Tcl Commands > classvariable

### Tcl/Tk Applications | Tcl Commands | Tk Commands | [incr Tcl] Package Commands | SQLite3 Package Commands | TDBC Package Commands | tdbc::mysql Package Commands | tdbc::odbc Package Commands | tdbc::postgres Package Commands | tdbc::sqlite3 Package Commands | Thread Package Commands | Tcl C API | Tk C API | [incr Tcl] Package C API | TDBC Package C API

### NAME

classvariable — 局所変数から級内の変数への連結を創生する Create link from local variable to variable in class

### 構文 SYNOPSIS

package require tcl::oo
classvariable variableName ?...?

### 説明 DESCRIPTION

classvariable 命令は手段の内部で利用可能である｡それは一つ或は多くの並んだ変数の名前を採り､それを手段の有効範囲内で利用可能にする; これらの変数の名前は修飾されていてはならなし､配列要素を参照していてはならない｡変数のもともとの有効範囲はそれに定義された手段の級の名前空間である｡言い替えると､参照された変数はその級の全ての具現値の間で共有される｡ The classvariable command is available within methods. It takes a series of one or more variable names and makes them available in the method's scope; those variable names must not be qualified and must not refer to array elements. The originating scope for the variables is the namespace of the class that the method was defined by. In other words, the referenced variables are shared between all instances of that class.

註意: この命令は､近似的に同じ目的の為の tcllib 内の snit 梱包によって提供される typevariable 命令に等価である｡もし級の具現値上で直接定義された手段内で(譬えば､ oo::objdefine 手段定義を通して)使われると､これは次の使用に非常に似ている: Note that 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

classvariable に列挙された､それぞれの変数｡ for each variable listed to classvariable.

### EXAMPLE

この級は如何に多くの具現値が作成されたかを勘定する｡ This class counts how many instances of it have been made.

    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

### SEE ALSO

global, namespace, oo::class, oo::define, upvar, variable

### KEYWORDS

class, class variable, variable
Copyright © 2011-2015 Andreas Kupries
Copyright © 2018 Donal K. Fellows