Navigation Menu

Skip to content

Commit

Permalink
doc coding-style: add about variable initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Mar 16, 2012
1 parent 3ef9d87 commit a82f0ec
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions doc/source/developer/coding_style.rst
Expand Up @@ -520,6 +520,20 @@ C++では真偽値に ``bool`` を使うためこのような状況は発生し
name_ = std::string(name);
}
変数宣言と同時に初期化する
^^^^^^^^^^^^^^^^^^^^^^^^^^

変数を宣言したときに同時に初期化する。宣言時に初期化せずに代入して初期化すると、無駄な処理が発生する可能性があるため非効率である。(後述)

よい例:

std::string name("users");

悪い例( ``std::string()`` のところでコンストラクターが動き、 ``name = ...`` のところで代入演算子が動いて2回初期化している):

std::string name;
name = std::string("users");

インクリメント・デクリメント
---------------------------

Expand Down

0 comments on commit a82f0ec

Please sign in to comment.