Original Post
From what I have read, the following code should compile correctly. Since ''i'' is declared within the scope of the for loop, it should go out of scope as soon as the for loop is done. Here is the code:
Now when I compile this code, I get the following error:
C:\Program Files\Microsoft Visual Studio\MyProjects\AmazingTank\Graphics.cpp(185) : error C2374: ''i'' : redefinition; multiple initialization
C:\Program Files\Microsoft Visual Studio\MyProjects\AmazingTank\Graphics.cpp(171) : see declaration of ''i''
I know when I do this in Java, this will compile correctly. I was under the impression that it is supposed to be legal in C++ as well. Am I wrong?
---
Make it work.
Make it fast.
"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
for(int i=0;i<12;i++) {
temp=buffer[i]*32;
source.top=(temp/512)*32;
source.left=(temp%32)*32;
source.top=((temp/512)+1)*32;
source.left=((temp%32)+1)*32;
dest.top=baseY;
dest.left=baseX+(i*32);
dest.bottom=baseY+32;
dest.right=baseX+((i+1)*32);
lpddsback->Blt(&dest,lpddsmenufont,&source,DDBLT_WAIT,NULL);
}
baseY+=32;
strcpy(buffer,"Campaign\0");
for(int i=0;i<8;i++) { // <<== compiler error occurs here
temp=buffer[i]*32;
source.top=(temp/512)*32;
source.left=(temp%32)*32;
source.top=((temp/512)+1)*32;
source.left=((temp%32)+1)*32;
dest.top=baseY;
dest.left=baseX+(i*32);
dest.bottom=baseY+32;
dest.right=baseX+((i+1)*32);
lpddsback->Blt(&dest,lpddsmenufont,&source,DDBLT_WAIT,NULL);
}
|