この文書の現在のバージョンと選択したバージョンの差分を表示します。
cli:initonly [2009/02/03 07:21] admin |
cli:initonly [2013/12/23 09:08] |
||
---|---|---|---|
ライン 1: | ライン 1: | ||
- | {{indexmenu_n>23}} | ||
- | ====== initonly ====== | ||
- | initonlyで宣言されたメンバはコンストラクタでのみ値を設定できます。initonly staticで宣言されたメンバはstaticコンストラクタのみ値を設定できます。 | ||
- | |||
- | <code cpp> | ||
- | ref class C | ||
- | { | ||
- | public: | ||
- | initonly static int x; | ||
- | initonly static int y; | ||
- | initonly int z; | ||
- | static C() | ||
- | { | ||
- | x = 1; | ||
- | y = 2; | ||
- | // z = 3; // Error | ||
- | } | ||
- | C() | ||
- | { | ||
- | // A = 2; // Error | ||
- | z = 3; | ||
- | } | ||
- | void sfunc() | ||
- | { | ||
- | // x = 5; // Error | ||
- | // z = 5; // Error | ||
- | } | ||
- | }; | ||
- | int main() | ||
- | { | ||
- | System::Console::WriteLine(C::x); | ||
- | System::Console::WriteLine(C::y); | ||
- | C c; | ||
- | System::Console::WriteLine(c.z); | ||
- | return 0; | ||
- | } | ||
- | </code> |