Results 1 to 4 of 4

Thread: [RESOLVED] MS VC++ Error?

  1. #1

    Thread Starter
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444

    [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.

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Try UINT

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  4. #4

    Thread Starter
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    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
  •  



Click Here to Expand Forum to Full Width