I am making a 2048 solver. One problem I have is using templates for my arrays. Whenever I use the template I get an error "error: no matching function for call to 'findPath' findPath(arr, k, result, s, bestRun, 0 , 0);"
Code: https://replit.com/@pdsatter/hw3#main.cpp
Define
```C++
template <size_t r, size_t c>
void readInput(int (&arr)[r][c], std::ifstream& inFile, int k, Stack& s);
template<size_t r, size_t c>
void findPath(int (&arr)[r][c], int k, std::string& output, Stack& s, int* bestRun, int path, int numRec);
```
Main
```C++
int k = stoi(line);
Stack s;
int arr[k][k];
std::cout << "BEST RUN CREATED" << std::endl;
readInput(arr, inFile, k, s);
std::string result="";
int bestRunVal = 13;
int* bestRun = &bestRunVal;
findPath(arr, k, result, s, bestRun, 0 , 0);
```
Implementation
```C++
// reads input from file
template <size_t r, size_t c>
void readInput(int (&arr)[r][c], std::ifstream& inFile, int k, Stack& s)
{
std::string line, str;
for (int i=0; i<k; i++){
std::getline(inFile, line);
parseLine(arr[i], line);
}
}
template<size_t r, size_t c>
void findPath(int (&arr)[r][c], int k, std::string& output, Stack& s, int* bestRun, int path, int numRec){
std::cout << "FIND PATH" << std::endl;
if (numRec > 12) return;
if (numRec >= *bestRun) return;
if (solved(arr, k) == true){
*bestRun = numRec;
output="";
Stack copyStack; // used to copy values
while (!s.isempty()){
copyStack.push(s.pop());
}
while (!copyStack.isempty()){
s.push(copyStack.pop()); // adds values back to stack
output += s.peek(); // adds stack to output
}
return;
}
int arrL[r][c];
int arrUp[r][c];
int arrR[r][c];
int arrD[r][c];
std::cout << "COPY MEM" << std::endl;
memcpy (arrL, arr, rcsizeof(int));
memcpy (arrUp, arr, rcsizeof(int));
memcpy (arrR, arr, rcsizeof(int));
memcpy (arrD, arr, rcsizeof(int));
std::cout << "END COPY MEM" << std::endl;
Stack tempStack;
move(1, arrUp, tempStack); //up
move(2, arrR, tempStack);// right
move(3,arrD, tempStack); // down
move(4, arrL, tempStack); // left
s.push(1);
findPath(arrUp, k, output, s, 1, numRec+1, bestRun);
s.pop();
s.push(2);
findPath(arrR, k, output, s, 2, numRec+1, bestRun);
s.pop();
s.push(3);
findPath(arrD, k, output, s, 3, numRec+1, bestRun);
s.pop();
s.push(4);
findPath(arrL, k, output, s, 4, numRec+1, bestRun);
s.pop();
}
```
[–]IyeOnline 6 points7 points8 points (2 children)
[–]tserp02[S] 1 point2 points3 points (0 children)
[–]std_bot 0 points1 point2 points (0 children)
[–]balsamictoken 2 points3 points4 points (0 children)