Per completezza, posto la soluzione che usa la classe:

Codice PHP:
#include <iostream>

using namespace std;

template <class T>
class 
Mat {
    private:
        
int n;
        
int m;
        
T** mat;
    public:
        
Mat(int p_nint p_m);
        ~
Mat();
        
int get_n();
        
int get_m();
        
Toperator() (int rowint col);
        
T operator() (int rowint col) const;
        
        
void init();
};

template <class T>
Mat<T>::Mat(int p_nint p_m) {
    
p_n;
    
p_m;
    
    
mat = new T*[n];
    
    for(
int i=0;i<n;i++) {
        
mat[i] = new T[m];
    }
}

template <class T>
Mat<T>::~Mat() {
    for(
int i=0;i<n;i++) {
        
delete(mat[i]);
    }
    
    
delete(mat);
}

template <class T>
int
Mat
<T>::get_n() {
    return 
n;
}

template <class T>
int
Mat
<T>::get_m() {
    return 
m;
}

template <class T>
TMat<T>::operator() (int rowint col) {
    if(
row >= || col >= m)
        throw 
"Out of range";
    return 
mat[row][col];
}

template <class T>
T Mat<T>::operator() (int rowint col) const {
    if(
row >= || col >= m)
        throw 
"Out of range";
    return 
mat[row][col];
}

template <class T>
void Mat<T>::init() {
    for(
int i=0i<n;i++) {
        for(
int j=0;j<m;j++) {
            
mat[i][j] = i*j;
        }
    }
}

template <class T>
void stampa(Mat<Tmat) {
    for(
int i=0;i<mat.get_n();i++) {
        for(
int j=0;j<mat.get_m();j++) {
            
cout << mat(i,j) << " | ";            
        }
        
cout << "\n";
    }    
}

int main() {
    
Mat<doublemat Mat<double>(3,4);
    
mat.init();    
    
stampa(mat);