The post C++ Scope reminded me of a question which has been bothering me for
very long. My compiler decided to do this:
for (int x = 0; x < 10; x++)
std::cout << x;
for (int x = 0; x < 20; x++) // illegal, redefinition of x
std::cout << x;
int x = 0; // legal
Would anyone tell me if this is the standard? No matter what order I put it
in, a second for loop cannot be defined with the same variable, but it can
be redefined outside of a for loop. Why is that? Please tell me this isn't
standard.
-- MiniDisc_2k2
To reply, replace nospam.com with cox dot net.
P.S. Where can I find a handbook or something telling me the C++ standard?
very long. My compiler decided to do this:
for (int x = 0; x < 10; x++)
std::cout << x;
for (int x = 0; x < 20; x++) // illegal, redefinition of x
std::cout << x;
int x = 0; // legal
Would anyone tell me if this is the standard? No matter what order I put it
in, a second for loop cannot be defined with the same variable, but it can
be redefined outside of a for loop. Why is that? Please tell me this isn't
standard.
-- MiniDisc_2k2
To reply, replace nospam.com with cox dot net.
P.S. Where can I find a handbook or something telling me the C++ standard?
Comment