Thread: Errors: ISO scoping, obsolete binding??

  1. #1
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79

    Errors: ISO scoping, obsolete binding??

    So I've finally learned enough to do the first code completion challenge, but when I try to compile and run it, I get a couple errors that I don't understand:


    Code:
    #include <iostream>
          using namespace std;
          int main()
    {
      int array[8];
      for(int x=0; x<8; x++)
      cin>>array[x];
      for(x=0; x<8; x++)
      cout<<array[x];
      return 0;
    }
    Line 8 name lookup of 'x' changed for new ISO 'for' scoping
    Line 6 using obsolete binding at 'x'

    Can somebody help me out here? Thanks -

    -JM
    Huh?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    You problem is that x is declared in the first for statement and it is no longer in scope when you reach the second for statement. The solution is to declare another variable for use with the second for statement or declare a variable outside both for statments and reset it to zero in both.

  3. #3
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    Earlier variables declared inside for loop were not use to die after the scope of for loop ended therefore we were able to use that variable .....but now according to new ISO standard....variable declared inside for loop die after the scope ends...and we can only use it if we declare it again.

  4. #4
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79
    Thanks, guys; now I understand.

    Funny, that's the official solution to the challenge yet it contains this error!

    There's always more to learn ....


    - JM
    Huh?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Help with ISO errors
    By alpha22 in forum C++ Programming
    Replies: 9
    Last Post: 02-18-2006, 05:10 PM
  3. Dev-cpp - compiler options
    By tretton in forum C Programming
    Replies: 7
    Last Post: 01-06-2006, 06:20 PM
  4. inet_aton()... Noob needs help with sockets :|
    By Maz in forum C++ Programming
    Replies: 3
    Last Post: 11-22-2005, 04:33 PM
  5. Static Binding & Dynamic Binding :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 12-31-2001, 08:51 PM