# Thread: No matching function for call to...

1. ## 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. 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);
}

3. 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 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;
}
}
}

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;
}
}
}

for(int i=0; i<numOfRow; i++){
for(int j=0; i<numOfCol; 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}};

return 0;
}

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

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.

5. Originally Posted by laserlight
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 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;
}
}
}

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;
}
}
}

for(int i=0; i<numOfRow; i++){
for(int j=0; i<numOfCol; 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}};

return 0;
}

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

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

10. Where is Quzah when you need him? <grin>

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

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

Where is Quzah when you need him? <grin>

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

13. 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. Originally Posted by 20120903
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!