【初心者歓迎】C/C++室 Ver.44【環境依存OK】at TECH
【初心者歓迎】C/C++室 Ver.44【環境依存OK】 - 暇つぶし2ch228:デフォルトの名無しさん
07/11/10 12:43:08
>>224
さっきから実装依存だと言ってるのって、名前空間スコープに定義した const 変数の
話じゃないの?

クラスの static const なメンバ変数はクラス定義内では宣言しかされないので、
別途定義が必要。整数型に限って、宣言につけた初期値を持つ定数式として使える
という特別ルールがあるだけ。

C++ 2003 規格の 9.4.2 p2 より
> The declaration of a static data member in its class definition is not a definition and may be of an
> incomplete type other than cv-qualified void. The definition for a static data member shall appear in a
> namespace scope enclosing the member’s class definition.

同じく 9.4.2 p4
> If a static data member is of const integral or const enumeration type, its declaration in the class
> definition can specify a constant-initializer which shall be an integral constant expression (5.19). In that
> case, the member can appear in integral constant expressions. The member shall still be defined in a namespace
> scope if it is used in the program and the namespace scope definition shall not contain an initializer.



次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch