2D Array: No matching function for call to

Hi, I'm taking my first C++ course and trying to call a 2D array of variable size in a function, but the compiler returns the error "No matching function for call to 'arrayname'". Any help much appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace std;

int size;

void mazesolve(int size, bool maze[size][size])
{ 
}

int main()
{
    do {
        cout << "Please input size of maze (a number between 4 and 20 is expected) -> ";
        cin >> size;
        if (size > 20 || size < 4) cout << "\n**Error** maze size not in range!\n";
        else cout << "\nPlease input contents of maze row by row, 1 for barrier and 0 for free passage.\n";
    } while (size > 20 || size < 4);
    
    bool maze[size][size];
    
    for (int i = 0; i < size; i++)
    {
        for (int j = 0; j < size; j++)
        {
            cin >> maze[i][j];
            cout << " ";
        }
        cout << endl;
    }
    
    mazesolve(size, maze);
}
Last edited on
First of all having array of size not known ic compile time is prohibited by C++. Many compilers have it as extension, but those are often not really consistent with all language constructs.

In your case you have an error because maze is a multidimensional array and size is not known at compile time.
Topic archived. No new replies allowed.