Ok, since I made the dumbest post, I have to fix it. Consider this code:
Code:
#include <iostream>
using namespace std;
int main()
{
for( int i = 0; i < 4; i++ )
{
cout << "You suck" << endl;
}
f = 9;
}
You got this error:
test.cpp: In function `int main()':
test.cpp:11: error: `f' undeclared (first use this function)
test.cpp:11: error: (Each undeclared identifier is reported only once for each
function it appears in.)
This is logic just as in Java with this code:
Code:
public class Tess
{
public static void main( String[] args )
{
for( int i = 0; i < 4; i++ )
{
System.out.println( "Damned" );
}
f = 9;
}
}
You got this error. Just same with C++. Only different language.
Tess.java:9: cannot resolve symbol
symbol : variable f
location: class Tess
f = 9;
^
1 error
But if you use this code:
Code:
#include <iostream>
using namespace std;
int main()
{
for( int i = 0; i < 4; i++ )
{
cout << "You suck" << endl;
}
i = 9;
}
You got unusual error. You didn't get this error:
test.cpp: In function `int main()':
test.cpp:11: error: `i' undeclared (first use this function)
test.cpp:11: error: (Each undeclared identifier is reported only once for each
function it appears in.)
But you got this error:
test.cpp: In function `int main()':
test.cpp:11: error: name lookup of `i' changed for new ISO `for' scoping
test.cpp:6: error: using obsolete binding at `i'
But in Java, the error is still the same with this code:
Code:
public class Tess
{
public static void main( String[] args )
{
for( int i = 0; i < 4; i++ )
{
System.out.println( "Damned" );
}
i = 9;
}
}
Tess.java:9: cannot resolve symbol
symbol : variable i
location: class Tess
i = 9;
^
1 error
Is there any good reason C++ handle this i different than Java?