C++ Templates – How to Invoke the C++ Template Function? [Duplicate]

c++templates

I am new to c++. can anyone please guide me how may I invoke the template function "debug" here.
The below code compiles fine.

#include <bits/stdc++.h>
using namespace std;

template<int m, int n>
void debug(int (&dp)[m][n]) {
    for(int i = 0; i < m; ++i) for(int j = 0; j <n; ++j) cout << dp[i][j] << " ";cout << endl;
}

void solve(string s, string t) {
    int n = s.size();
    int m = t.size();
    int dp[m][n];
    for(int i = 0; i < m; ++i) for(int j = 0; j <n; ++j) dp[i][j] = -1;
    //debug<m,n>(dp);
}

int main() 
{
    string s = "abbdbdbbdjhsd";
    string t = "98389";
    solve(s, t);
    return 0;
}

just needed to invoke the function.

getting below error

/Users/nkumari3/C++/r.cpp:14:2: error: no matching function for call to 'debug'
        debug<m,n>(dp);
        ^~~~~~~~~~
/Users/nkumari3/C++/r.cpp:5:6: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'm'
void debug(int (&dp)[m][n]) {
     ^
1 error generated.

Best Answer

Not possible to invoke at compile time.