3

次の行でエラーが発生するのはなぜですか?

for(int i = 0, int pos = 0, int next_pos = 0; i < 3; i++, pos = next_pos + 1) {
  // …
}

error: expected unqualified-id before ‘int’
error: ‘pos’ was not declared in this scope
error: ‘next_pos’ was not declared in this scope

コンパイラはg++です。

4

2 に答える 2

15

ステートメントごとに持つことができる宣言のタイプは1つだけなので、必要なintは1つだけです。

for(int i = 0, pos = 0, next_pos = 0; i < 3; i++, pos = next_pos + 1)
于 2010-08-01T22:19:44.803 に答える
4

通常のプログラムでは:

int main()
{

int a=0,int b=0,int c=0;
return 0;    

}

動作することはなく、受け入れられません。

これは、forループ内で実際に実行しようとしていることです。

于 2010-08-02T08:01:26.163 に答える