Erik Tena Erik Tena - 1 year ago 68
C++ Question

no matching function call in C++, need fresh pair of eyes

I am building a C++ project for fun and I have the following error: No matching function for call to 'loopAction' I have spent about 1.5 hours trying to figure this out and reading through Stack overflow about what could be the issue. I am hoping that an extra set of eyes will help me find the issue.

I have the following prototype in my program:

//Global Constants
const int ROWS = 100;
const int COLS = 100;

void loopAction(fstream &, int [][COLS], int, int, int);

In the above example, fstream is a file object, int [][] is a 2-d array, and the three last values are variables.

Variables that I have declared:

ifstream File;"deskInfo.txt");

int n, m;
char theValues[ROWS][COLS];

Here is the call to my function:

loopAction(File, theValues, ROWS, n, m);

And the actual function:

void loopAction(fstream &file, int values[][COLS], int rows, int n, int m){
char row;

for (int r = 0; r < n; r++){
for (int c = 0; c < m; c++){
file >> row;
values[r][c] = row;


Please let me know if more information is needed. The full error message is:

Semantic issue, No matching function for call to '
' =>
Candidate function not viable: no known conversion from '
' (aka '
') to '
fstream &
' (aka '
basic_fstream<char> &
') for 1st argument

Dai Dai
Answer Source

theValues is typed as char[][] but the method signature accepts int[][].

A few other tips unrelated to your original question:

  • Use templated methods to prevent array-decay, which would help in this situation (see below)
  • Prefer const to #define
  • Be consistent in your naming and capitalization conventions: you're using the Title-cased File seemingly arbitarily compared to your other pascalCased identiifers.
  • Put parameter names in your method declarations

Array decay (how foo[N] turns to foo*) can be prevented by accepting an array type (with size) as a template argument:

template<typename TArray>
void loopAction(fstream& file, TArray& values, size_t n, size_t m)

This way you don't need to use ROWS and COLS, you can use sizeof correctly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download