Thread: error : declaration of 'float finalArray[9][9]' shadows a parameter

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    54

    error : declaration of 'float finalArray[9][9]' shadows a parameter

    Hi everyboy ! While compiling, i get this error :
    error : declaration of 'float finalArray[9][9]' shadows a parameter
    I don't understand where does it come from. Here is my code :
    Code:
    #include <iostream>#include <iomanip>
    #include <cstdlib>
    
    
    using namespace std;
    
    
    
    
    void initArray(float largeArray[6][6]){
        for (int x=0; x < 6; x++){
                for (int y=0; y<6; y++){
                      largeArray[x][y] = 0;
            }
        }
    
    
    
    
    }
    
    
    
    
    float printOutArray(float largeArray[6][6]){
        for (int x = 0; x < 6; x++){
    
    
    
    
                for (int y = 0; y < 6; y++){
                        cout << largeArray [x] [y]<<'\t';
                    }
               cout << endl;
            }
    return largeArray[6][6];
    }
    
    
    float tata (int degree_denominator, float largeArray[6][6] )
    {
    float array_of_coefficients[6];
    int c=0;
    int l=0;
    int x;
    for (x=degree_denominator ; x>=0 ; x--){
                                            if (l==2){l=0;c++;}
                                   cout << "what is the coefficient linked with degree" << x << "?" << endl;
                                   cin >> array_of_coefficients[x];
                                   largeArray[l][c] = array_of_coefficients[x];
                                   l++;
                                  }
    
    
     return largeArray[6][6];
    }
    
    
    
    
    float toto(float largeArray[6][6], float finalArray[9][9])
    {
    float finalArray[9][9] = {0};
    int line = 0;
    int i = 0;
    int r = line -2;
    int s = line - 1;
    int f = i + 1;
    
    
    for (line = 0; line <= 1 ; line ++){
                     for (i = 0; i<=6; i++){
                                    finalArray[line][i] = largeArray[line][i];
                     }
      }
    
    
    for (line = 2; line <= 9 ; line ++){
            for (i = 0; i<=6; i++){
                                    finalArray[line][i] = ((finalArray[line][i]) - ( ( finalArray[s][f] ) * ( (finalArray[r][i])/ (finalArray[s][i])) ) ) ;
                                    }
                          }
    
    
    
    
    return finalArray[9][9];
    }
    
    
    
    
    
    
    float printOutArray2(float finalArray[9][9]){
        for (int x = 0; x <= 9; x++){
    
    
    
    
                for (int y = 0; y <= 9; y++){
                        cout << finalArray [x] [y]<<'\t';
                    }
               cout << endl;
            }
    return finalArray[9][9];
    }
    
    
    
    
    int main()
    {
        float finalArray [9][9];
        float largeArray [6][6];
        initArray(largeArray);
        printOutArray(largeArray);
        int degree_denominator;
        cout << "what is the degree of the denominator?" << endl;
        cin >> degree_denominator;
        tata(degree_denominator, largeArray);
        printOutArray(largeArray);
        toto(largeArray,finalArray);
        cout << "final array:" << endl;
        printOutArray2(finalArray);
        system("PAUSE");
    
    
    }
    Thank you in advance for your help!

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Your indentation is all over the place not sure if you have neglected to paste as text but fix it up.

    Code:
    return largeArray[6][6];
    This is not right - unless you are trying to just return the value at n,n in the array? arrays are passed by reference, changes made in the function definition affect the data passed in.
    Your function declares that it returns a float?, but you dont even try and use the result of that in the call.

    function names like toto and tata are not very good - it does not tell anybody, including you in the future, what it is supposed to do
    Last edited by rogster001; 03-18-2013 at 01:41 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    54
    Yes, i just want to return each value of the array at n,n

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Try commenting out line 63 (line number referenced to the code in the first post).

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Try commenting out line 63 (line number referenced to the code in the first post).
    Yes, the array is passed by reference as an argument to the function - you then try and declare another, identical local array of the same name. causing conflict.

    Yes, i just want to return each value of the array at n,n
    EACH? value at N, N ? If you just want to be able to access all the changes made in your array then you simply have to pass it in and work with it, no return type is neccesary.
    If however you want to return ONE value that has been stored in your array as a result of the function work, then yes just return the float at whatever postion that value is stored at after processing. But you still have to assign or evaluate the value back at the function call or it is pointless trying to return it.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  6. #6
    Registered User
    Join Date
    Feb 2013
    Posts
    54
    Yes, but the problem is i think i have to pass finalArray because i use it in my function toto, but contrarily to what you said i want to return each value of the array finalArray in the code coming next, that's why i wanted to return finalArray at the end of my function toto. So how should i do it?

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by rogster001 View Post
    ...arrays are passed by reference...
    No, they are not. They decay to a pointer to the first element, so they are passed by address or pointer. Weird? Yes, I know. For some reason the C designers thought that you should always pass arrays by pointer and never by value. This silliness has been corrected in C++11 with std::array. With std::array, you can choose to pass it by value, reference or pointer. You can also copy it, whereas with C arrays, you cannot (you have to copy element-wise).
    You can actually pass an array as a reference in C++, but that has an alternate syntax:

    void foo(T (&myarray)[N][M])

    Where T is the type and N and M are the dimensions of a 2D array.
    Last edited by Elysia; 03-18-2013 at 03:17 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Template parameter is incompatible with the declaration
    By Elysia in forum C++ Programming
    Replies: 9
    Last Post: 04-06-2010, 04:53 AM
  2. Replies: 6
    Last Post: 01-08-2008, 10:25 AM
  3. declaration of "blah" shadows a parameter??
    By ilikepure in forum C++ Programming
    Replies: 3
    Last Post: 05-21-2007, 10:21 AM
  4. cannot start a parameter declaration
    By Dark Nemesis in forum C++ Programming
    Replies: 6
    Last Post: 09-23-2005, 02:09 PM
  5. Replies: 8
    Last Post: 07-08-2005, 09:12 AM