Well, while we''re on the topic of scope... I think someone referred to this above, but I wasn''t sure. When I do something like this:
for (int i = 0; i < 10; i++)
{
for (int j = 0l j < 10; j++)
{}
}
And then I do something later on, such as:
for (int i = 0; i < 10; i++)
{}
I believe that, sometimes, I get the "error C2374: ''i'' : redefinition; multiple initialization" message. Shouldn''t the first i disappear after the first ''for'' is finished? Is this the bug with ''for'' in MSVC that Oluseyi was referring to?
why cant i assign a value to a variable when its created
Bingo.
You can get it around it with this, though:
#define for if(0) {} else for
You can get it around it with this, though:
#define for if(0) {} else for
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
The standard says that the first i should, indeed, leave scope. However, MSVC++ follows the recomendation form an earlier version of the standard that says that for loop variable are visible within the scope surrounding the for... Kinda silly - but that''s how it works. I have been told that Dev-C++ follows the newer version of the standard.
God was my co-pilot but we crashed in the mountains and I had to eat him...
Landsknecht
God was my co-pilot but we crashed in the mountains and I had to eat him...
Landsknecht
My sig used to be, "God was my co-pilot but we crashed in the mountains and I had to eat him..."
But folks whinned and I had to change it.
But folks whinned and I had to change it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement