Created
October 21, 2014 23:23
-
-
Save TSKGunGun/c445b333ca5105e3a884 to your computer and use it in GitHub Desktop.
ループ内変数について
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<string.h> | |
using namespace std; | |
void function(){ | |
//ループ内で変数を宣言する | |
for( int ii(0); ii < 0; ii++ ){ | |
string str = _T("IN") | |
} | |
/*スコープが狭い | |
コンストラクタ・デストラクタがループの数だけコールされる*/ | |
//ループの外で変数を宣言する | |
string str; | |
for( int ii(0); ii < 0; ii++ ){ | |
str = _T("OUT") | |
} | |
/* スコープが広い | |
コンストラクタ・デストラクタは1回だけ*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
元ネタ:Effective C++ 26項