Error message "name lookup of 't' changed for ISO 'for' scoping"??
Nov 28, 2011 at 1:33am UTC
Here is the code that causes it:
1 2 3
for (int t = _T_START; t != _T_END; t++) { // error
cout <<t;
}
where
_T_START
and
_T_END
are #defined. removing these and using numbers seems to fix the problem:
1 2 3
for (int t = 0; t != 10; t++) { //works fine
cout <<t;
}
also declaring
t
outside the loop doesn't help:
1 2 3 4
int t;
for (t = _T_START; t != _T_END; t++) { //fail
cout <<t;
}
I'd really appreciate if someone could tell me what on earth is going on here, thanks!
Nov 28, 2011 at 1:38am UTC
Where did you find these macros and why do you use them?
Nov 28, 2011 at 1:41am UTC
What do you mean by macro? I defined the _T_START and _T_END values myself. Interestingly, the following does work:
1 2 3 4 5
int t = _T_START;
for (; t != _T_END; t++) { // works!
cout <<t;
}
So the problem doesn't seem to be the #defined values, but rather something about scoping that the compiler doesn't like, I just don't see what it could be...
Last edited on Nov 28, 2011 at 1:42am UTC
Nov 28, 2011 at 1:54am UTC
ah crud my bad; I had semicolons after my #define statements for those values:
1 2
#define _T_START 1; //bad!
#define _T_END 20; //bad!
Last edited on Nov 28, 2011 at 1:55am UTC
Nov 28, 2011 at 2:24am UTC
This is one of the reasons why you should prefer const
for constants.
Last edited on Nov 28, 2011 at 2:24am UTC
Topic archived. No new replies allowed.