Results 1 to 3 of 3

Thread: Whats up with this weird error? it says somthing about obsolite binding?(arrays)

  1. #1

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Question

    Hello everyone, i don't understand whats wrong with this example....

    Code:
    #include <iostream.h>
    
    void main(){
         double a[4];
         cout << "enter 4 real numbers: \n";
         for (int i = 1; i <=4; i++) {
         cout << i << ": ";
         cin >> a[i-1];
    
         }
         cout << "Here they are in reverse order:\n";
         for (i = 3; i >= 0; i--)
         cout << "\ta[" << i << "] = " << a[i] << endl;
         }

    I get the following errors:
    c:\my documents\c++programs\programming in c++\array's\printing array numbers.cpp: In function `int main(...)':
    c:\my documents\c++programs\programming in c++\array's\printing array numbers.cpp:13: name lookup of `i' changed for new ANSI `for' scoping
    c:\my documents\c++programs\programming in c++\array's\printing array numbers.cpp:7: using obsolete binding at `i'
    c:\my documents\c++programs\programming in c++\array's\printing array numbers.cpp: In function `int main(...)':
    c:\my documents\c++programs\programming in c++\array's\printing array numbers.cpp:16: redefinition of `int main(...)'
    c:\my documents\c++programs\programming in c++\array's\printing array numbers.cpp:4: `int main(...)' previously defined here
    c:\my documents\c++programs\programming in c++\array's\printing array numbers.cpp: In function `int main(...)':
    c:\my documents\c++programs\programming in c++\array's\printing array numbers.cpp:25: name lookup of `i' changed for new ANSI `for' scoping
    c:\my documents\c++programs\programming in c++\array's\printing array numbers.cpp:19: using obsolete binding at `i'

    thanks for listenign

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Under VC++ (just tested it) it's fine.

    Using Borland C++ 5.5.1 it gives me an "undefined symbol 'i' in function main()" error.

    Changing it to this worked on Borland:
    Code:
    #include <iostream.h>
    
    void main(){
    	double a[4];
    	int i;
    	cout << "enter 4 real numbers: \n";
    	for (i = 1; i <= 4; i++) {
    		cout << i << ": ";
    		cin >> a[i-1];
    	}
    
    	cout << "Here they are in reverse order:\n";
    
    	for (i = 3; i >= 0; i--)
    		cout << "\ta[" << i << "] = " << a[i] << endl;
    }
    This is because under ANSI rules, variable declaration does not move out a for block, and must either be declared twice or once globally.

    Turning off MS extensions in VC++ also produced this error.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Talking thanks !

    Works great now, thanks!

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