No matching function for call to...

This is a discussion on No matching function for call to... within the C Programming forums, part of the General Programming Boards category; Hello. I have a problem when I invoke a function in the main function. The problem is "No matching function ...

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    7

    No matching function for call to...

    Hello. I have a problem when I invoke a function in the main function. The problem is "No matching function for call to that function". I don't know why it states no matching function when the function does exist. Thank you for help.

    Code:
    int* f1(int **a, int b, int c){
        int d[5];
        return d;
    }
    
    int main(){
        int e[5];
        int f[5][5];
        e = &f1(f, 1, 2);
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,183
    The problem is that the first parameter of f1 is a pointer to a pointer to int. However, you call f1 by passing f as the first argument. f is an array of 5 arrays of 5 ints, thus it is converted to a pointer to an array of 5 ints, which certainly is not a pointer to a pointer to int.

    Next, in f1, d is local to f1 and hence does not exist after f1 returns, but then you return a pointer to the first element of d.

    My guess is that you really want to do something like this instead:
    Code:
    void f1(int (*a)[5], int b, int c, int *d) {
        // ...
    }
     
    int main(void) {
        int e[5];
        int f[5][5];
        f1(f, 1, 2, e);
    }
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    7
    Thank you.
    There is still an error if I changed **a to a[][] as suggested.
    This is my original code.
    I dont't know why it states No matching function for call to findSaddlePoints.Thanks
    Code:
    
    #include <stdio.h>
    
    
    int* findSaddlePoints(int **arr, int numOfRow, int numOfCol){
        int ans[numOfRow * numOfCol];
        int saddlePoint[numOfRow][numOfCol];
        int littleRow = arr[0][0];
        int maxCol = arr[0][0];
        int littleRowPosition;
        int maxColPosition;
        int m = 0;
        
        for (int i=0; i<numOfRow; i++){
            for (int j=0; j<numOfCol; j++){
                if(arr[i][j] < littleRow){
                    littleRow = arr[i][j];
                    littleRowPosition = j;
                }
            }
            saddlePoint[i][littleRowPosition]++;
        }
        
        for (int j=0; j<numOfCol; j++){
            for (int i=0; i<numOfRow; i++){
                if(arr[i][j] > maxColPosition){
                    maxCol = arr[i][j];
                    maxColPosition = i;
                }
            }
            saddlePoint[maxColPosition][j]++;
        }
        
        for(int i=0; i<numOfRow; i++){
            for(int j=0; i<numOfCol; j++){
                if(saddlePoint[i][j] == 2){
                    ans[m] = saddlePoint[i][j];
                    m++;
                }
            }
        }
        
        return ans;
    }
    
    
    
    
    int main(void){
        int arr[6][8]={{11,33,55,16,77,99,10,40},
            {29,87,65,20,45,60,90,76},{50,53,78,44,60,88,77,81},
            {46,72,71,23,88,26,15,21},{65,83,23,36,49,57,32,14},
            {40,22,34,19,54,37,26,93}};
        int answer[sizeof(arr[0])/sizeof(arr[0][0]) * sizeof(arr)/sizeof(arr[0])];
        
        answer = &findSaddlePoints(arr, sizeof(arr[0])/sizeof(arr[0][0]), sizeof(arr)/sizeof(arr[0]));
        
        return 0;
    }

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,183
    Quote Originally Posted by 20120903
    There is still an error if I changed **a to a[][] as suggested.
    Show the code that you tried and the exact error message.

    Quote Originally Posted by 20120903
    This is my original code.
    I dont't know why it states No matching function for call to findSaddlePoints.
    The same reason as in your example code.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Sep 2012
    Posts
    7
    Quote Originally Posted by laserlight View Post
    Show the code that you tried and the exact error message.
    The error is shown below. Thank you.
    Code:
    
    #include <stdio.h>
    
    
    int* findSaddlePoints(int *arr[], int numOfRow, int numOfCol){
        int ans[numOfRow * numOfCol];
        int saddlePoint[numOfRow][numOfCol];
        int littleRow = arr[0][0];
        int maxCol = arr[0][0];
        int littleRowPosition;
        int maxColPosition;
        int m = 0;
        
        for (int i=0; i<numOfRow; i++){
            for (int j=0; j<numOfCol; j++){
                if(arr[i][j] < littleRow){
                    littleRow = arr[i][j];
                    littleRowPosition = j;
                }
            }
            saddlePoint[i][littleRowPosition]++;
        }
        
        for (int j=0; j<numOfCol; j++){
            for (int i=0; i<numOfRow; i++){
                if(arr[i][j] > maxColPosition){
                    maxCol = arr[i][j];
                    maxColPosition = i;
                }
            }
            saddlePoint[maxColPosition][j]++;
        }
        
        for(int i=0; i<numOfRow; i++){
            for(int j=0; i<numOfCol; j++){
                if(saddlePoint[i][j] == 2){
                    ans[m] = saddlePoint[i][j];
                    m++;
                }
            }
        }
        
        return ans;
    }
    
    
    
    
    int main(void){
        int arr[6][8]={{11,33,55,16,77,99,10,40},
            {29,87,65,20,45,60,90,76},{50,53,78,44,60,88,77,81},
            {46,72,71,23,88,26,15,21},{65,83,23,36,49,57,32,14},
            {40,22,34,19,54,37,26,93}};
        int answer[sizeof(arr[0])/sizeof(arr[0][0]) * sizeof(arr)/sizeof(arr[0])];
        
        answer = &findSaddlePoints(arr, sizeof(arr[0])/sizeof(arr[0][0]), sizeof(arr)/sizeof(arr[0])); //error: No matching function for call to 'findSaddlePoints'
        
        return 0;
    }

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Compare your line 9 in your call to the function, with laserlight's example, on line 8. One char is a problem.

    You could use a[][5] as the parameter in f1(), but a[][] should give you a warning or an error: Missing array size.

  7. #7
    Registered User
    Join Date
    Sep 2012
    Posts
    7
    Quote Originally Posted by Adak View Post
    Compare your line 9 in your call to the function, with laserlight's example, on line 8. One char is a problem.

    You could use a[][5] as the parameter in f1(), but a[][] should give you a warning or an error: Missing array size.
    Thank you. But error still exists in line 9 after I changed it to a[][100]

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You haven't zeroed in on the wrong char on line 9 of your first example, yet.

    I know you will find it - I hope so, because I am NOT telling you. Find the char that you have, (still), that laserlight's example function call line of code does NOT have.

    Hunt it down!

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,183
    Quote Originally Posted by 20120903
    But error still exists in line 9 after I changed it to a[][100]
    You're talking about the code that you posted in post #1? If so, where did you get 100 from?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Where is Quzah when you need him? <grin>

    It's odd, but I do miss him on the forum.

  11. #11
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,752
    You cannot assign arrays, so the return value of FindSaddlePoints, f1, whatever does not make any sense. Stop trying to do that. I suggest you look at the code in post #2 again, instead of trying to return arrays to be assigned later.

  12. #12
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,752
    Quote Originally Posted by Adak View Post
    Where is Quzah when you need him? <grin>

    It's odd, but I do miss him on the forum.
    He's around.

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    There are 3 char's difference between his line 9, and laserlight's line number 8.

    One wonders how long it could possibly take, to find the culprit char?

    OGK, and HE ain't telling, I guess. My patience is gone!

    Thanks for the update, whiteflags.

  14. #14
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Quote Originally Posted by 20120903 View Post
    Thank you. But error still exists in line 9 after I changed it to a[][100]
    Well that makes sense, and I'm glad the compiler is complaining about that since I don't see and array containing a 2D array 100 columns wide anywhere in your code.
    I can see one that is 8 columns wide though, or 5 in the first example you posted. Hmm, maybe one those numbers would fix the compilation error...

    A pity that the code is still horribly broken after that fix though since you're returning the address of a local variable. That spells doom!
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Constructors: No Matching function for call error
    By Emilio Martin in forum C++ Programming
    Replies: 5
    Last Post: 03-22-2012, 01:49 PM
  2. Replies: 8
    Last Post: 07-08-2011, 02:16 PM
  3. No Matching Function Call for Constructor
    By manasij7479 in forum C++ Programming
    Replies: 5
    Last Post: 02-07-2011, 03:29 PM
  4. Replies: 2
    Last Post: 02-27-2009, 12:46 PM
  5. no matching function for call to
    By f6ff in forum C++ Programming
    Replies: 4
    Last Post: 06-10-2006, 04:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21