我使用Visual Studio 2010中,當我這樣做視覺未申報的標識符?
for(int i = 0, j = 0; i < 10; i++)
{
if(m_Var == 1)
j++;
}
if(j == 0)//This line errors undeclared identifier
DoSomething();
我已經宣佈在for循環j
所以爲什麼它示數「未聲明的標識符」?
另一個例子是
for(int i = 0; i < 10; i++)
{
m_Var1++;
}
for(i = 0; i < 200; i++)//This line errors undeclared identifier
{
m_Var2++;
}
代碼錯誤,即使它被宣佈for循環,但是爲什麼呢?有沒有辦法做到這一點,而不必在循環之前聲明i
,而是在循環中聲明它,而不是像上面的例子中那樣?
對於第二個例子,無論如何,在兩個循環中定義'i'都是更好的樣式。 –