|
-
Aug 30th, 2002, 09:58 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] MS VC++ Error?
Hi, I'm new to C++, and I was just testing out arrays. I made a 2D array, and had the following code to get the user to fill the arrays, and then read it back:
Code:
for (USINT loopcounter1 = 0; loopcounter1 < 3; loopcounter1++)
{
for (USINT loopcounter2 = 0; loopcounter2 < 3; loopcounter2++)
{
cout << "Please enter a number for " <<
"[" << loopcounter1 << "]" <<
"[" << loopcounter2 << "]: ";
cin >> numbers[loopcounter1][loopcounter2];
}
}
cout << "Thank you\n";
for (USINT loopcounter1 = 0; loopcounter1 < 3; loopcounter1++)
{
for (USINT loopcounter2 = 0; loopcounter2 < 3; loopcounter2++)
{
cout << "Item [" << loopcounter1 << "]" <<
"[" << loopcounter2 << "] = " <<
numbers[loopcounter1][loopcounter2] <<
endl;
}
}
But Microsoft Visual C++ gave me a compile error at the bolded text that USINT loopcounter1 had already been declared on the first loop. I may be wrong here but I should declare it again shouldn't I as it's gone out of scope and has been destroyed. I compiled the same prog in Dev-C++ and it compiled without an error, who's right?
Last edited by Rick Bull; Aug 30th, 2002 at 11:38 AM.
-
Aug 30th, 2002, 10:14 AM
#2
Frenzied Member
-
Aug 30th, 2002, 10:20 AM
#3
That's a thing that recently changed in the standard.
In early C++ standards a variable declared inside a for-statement:
for(int i=0;...)
was supposed to be in the surrounding scope. Since a recent change it is supposed to be in the inner scope, the one between the brackets of the for-statement.
But to be honest, even VC++7 follows the old standard. To be on the safe side it is usually best to declare loop variables once at the start of the function (like in C) and be done with it.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Aug 30th, 2002, 11:38 AM
#4
Thread Starter
Frenzied Member
Oh thanks guys. I've found a few things I've thought to be bugs, but I assume that it's just that VC++ isn't ANSI standard, is that right?
And the USINT is a typedef I made at the top of the program, just thought it was all irrelevant so I cut it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|