c++ dynamic array initialization with declaration
c++, dynamic-arrays
Solution
Technically, a 2D array is an array of 1D arrays. So it cannot convert into pointer to pointer. It can convert into pointer to array, though.
So this should work:
void findScarf1(bool (*matrix)[7], int m, int n, int radius, int connectivity);
Here `bool (*matrix)[7]` declares a pointer to array of 7 bool.
Hope that helps.
Problem
I have function like this: ``` void findScarf1(bool ** matrix, int m, int n, int radius, int connectivity); ``` and in main function I create 2d dynamic array to pass in this function ``` bool matrix[6][7] = { {0, 0, 1, 1, 1, 0, 0}, {0, 0, 1, 1, 1, 0, 0}, {0, 0, 1, 1, 1, 0, 0}, {0, 0, 1, 1, 1, 0, 0}, {0, 0, 1, 1, 1, 0, 0}, {0, 0, 1, 1, 1, 0, 0} }; ``` The problem is: ``` findScarf1(matrix, 6, 7, 3, 4); ``` causes error C2664: 'findScarf1' : cannot convert parameter 1 from 'bool [6][7]' to 'bool **' How to initialize array compactly(simultaneously with declaration)? p.s. sorry if it's duplicate question but I've spent 1.5 hours figuring it out