[表示 : 全て 最新50 1-99 101- 201- 301- 401- 501- 2ch.scのread.cgiへ]
Update time : 03/25 20:45 / Filesize : 142 KB / Number-of Response : 589
[このスレッドの書き込みを削除する]
[+板 最近立ったスレ&熱いスレ一覧 : +板 最近立ったスレ/記者別一覧] [類似スレッド一覧]


↑キャッシュ検索、類似スレ動作を修正しました、ご迷惑をお掛けしました

C++相談室 part123



43 名前:デフォルトの名無しさん mailto:sage [2016/02/22(月) 23:33:38.04 ID:/YQF/sqY.net]
>>42
n3690から抜粋すると
8.5.17:The semantics of initializers are as follows. The destination type is the type of the object or reference being
initialized and the source type is the type of the initializer expression. If the initializer is not a single (possibly
parenthesized) expression, the source type is not defined.
— If the initializer is a (non-parenthesized) braced-init-list, the object or reference is list-initialized
8.5.4.3: List-initialization of an object or reference of type T is defined as follows:
if the initializer list has no elements and T is a class type with a default constructor, the
object is value-initialized.
8.5.8: To value-initialize an object of type T means:
— if T is a (possibly cv-qualified) class type (Clause 9) with either no default constructor (12.1) or a
default constructor that is user-provided or deleted, then the object is default-initialized
8.5.7: To default-initialize an object of type T means:
— if T is a (possibly cv-qualified) class type (Clause 9), the default constructor (12.1) for T is called

つまりこの場合に限ると
・リストで初期化するとlist-initializeされる。
・リストが空の場合、list-initializeはvalue-initializeになる。
・デフォルトコンストラクタが削除されてたり、ユーザ定義されてる場合はvalue-initializeはdefault-initializeになる。
・default-initializeはデフォルトコンストラクタを呼び出す
・hoge::hoge()は何も実行しない→hoge::bakaは未定義のままになる
といった具合。

解決するには、
hoge() : baka(0) {return;}
みたいにちゃんと初期化コードを書かなきゃ駄目。






[ 続きを読む ] / [ 携帯版 ]

全部読む 次100 最新50 [ このスレをブックマーク! 携帯に送る ] 2chのread.cgiへ
[+板 最近立ったスレ&熱いスレ一覧 : +板 最近立ったスレ/記者別一覧]( ´∀`)<142KB

read.cgi ver5.27 [feat.BBS2 +1.6] / e.0.2 (02/09/03) / eucaly.net products.
担当:undef