I am having issues with running this code. It's supposed to be a templated 2D array with constructors, destructors, copy constructors, and operator overloads. 

My main issue is in the `ostream& operator<<(ostream& os, SafeMatrix<class T> s)` overloader that's causing the errors. In main, when I `cout<<b[0][0]`, it prints fine, but when i do it in the `ostream& operator<<(ostream& os, SafeMatrix<class T> s)` overloader, I get errors. I am trying to just print the object like `cout << b` as you can see in main.

There's probably a lot of coding mistakes. Sorry, I'm new to templates and overloading. I have been reading and reading and can't find anything that is relevant to my project.

```
#include <iostream>
#include <cstdlib>
#include <cassert>

using namespace std;
template <class T> class SafeMatrix{
private:
    int row_low, row_high, col_low, col_high;
    T** p;
public:

    // default constructor
    // allows for writing things like SafeMatrix a;
    SafeMatrix() : row_low(0), row_high(-1)
        , col_low(0), col_high(-1), p(nullptr){ }

    // 1 parameter constructor
    // SafeMatrix (10);
    SafeMatrix(int dim){
        if (dim <= 0){
            cout << "constructor error in bounds definition" << endl;
            exit(1);
        }
        row_low = 0; row_high = dim - 1;
        col_low = 0; col_high = dim - 1;
        p = new T*[dim];
        for (int i = 0; i < dim; i++)
            p[i] = new T[dim];
    }

    // 2 parameter constructor lets us write
    // SafeMatrix (10,20);
    SafeMatrix(int row, int col){
        if (row <= 0 || col<=0){
            cout << "constructor error in bounds definition" << endl;
            exit(1);
        }
        row_low = 0; row_high = row - 1;
        col_low = 0; col_high = col - 1;
        p = new T*[row];
        for (int i = 0; i < row; i++)
            p[i] = new T[col];
    }

    // 2 parameter constructor lets us write
    // SafeMatrix (10,20);
    SafeMatrix(int row_low, int row_high, int col_low, int col_high){
        if ((row_high - row_low + 1) <= 0 || (col_high - col_low + 1) <= 0){
            cout << "constructor error in bounds definition" << endl;
            exit(1);
        }
        this.row_low = row_low; this.row_high = row_high - 1;
        this.col_low = col_low; this.col_high = col_high - 1;
        p = new T*[(col_high - col_low) + 1];
        for (int i = 0; i <= row_high-row_low; i++)
            p[i] = new T[(col_high - col_low) + 1];
    }

    // copy constructor for pass by value and
    // initialization
    SafeMatrix(const SafeMatrix &s){
        int row = (s.row_high - s.row_low) + 1,
            col = (s.col_high - s.col_low) + 1;
        p = new T*[row];
        for (int i = 0; i < row; i++)
            p[i] = new T[col];
        for (int i = 0; i < row; i++)
            for (int j = 0; j < col;j++)
                p[i][j] = s.p[i][j];
        row_low = s.row_low; row_high = s.row_high;
        col_low = s.col_low; col_high = s.col_high;
    }

    // destructor
    ~SafeMatrix(){
        for (int i = 0; i < (row_high - row_low) + 1; i++)
            delete[] p[i];
        delete[] p;
    }

    friend class Brackets;

    //overloaded [] lets us write
    //SafeMatrix x(10,20); x[15]= 100;
    class Brackets {
    private:
        T* p1;
    public:
        Brackets(T* p2) : p1(p2) { }

        T& operator[](int i) {
            /*if (i<col_low || i>col_high) {
                cout << "index " << i << " out of range" << endl;
                exit(1);
            }*/
            return p1[i];
        }
    };

    Brackets operator[](int i) {
        if (i<row_low || i>row_high) {
            cout << "index " << i << " out of range" << endl;
            system("pause");
            exit(1);
        }
        return Brackets(p[i]);
    }

    // overloaded assignment lets us assign
    // one SafeMatrix to another
    SafeMatrix& operator=(const SafeMatrix & s){
        if (this != &s){
            delete[] p;
            int row = (s.row_high - s.row_low) + 1,
                col = (s.col_high - s.col_low) + 1;
            p = new T*[row];
            for (int i = 0; i < col; i++)
                p[i] = new T[col];
            for (int i = 0; i < row; i++)
                for (int j = 0; j < col; j++)
                    p[i][j] = s.p[i][j];
            this.row_low = s.row_low; this.row_high = s.row_high;
            this.col_low = s.col_low; this.col_high = s.col_high;
        }
        return *this;
    }

    // overloads << so we can directly print SafeMatrix
    friend ostream& operator<<(ostream& os, const SafeMatrix<T> s);

};

ostream& operator<<(ostream& os, SafeMatrix<class T> s){
    int row = (s.row_high - s.row_low) + 1,
        col = (s.col_high - s.col_low) + 1;
    for (int i = 0; i < row; i++){
        for (int j = 0; j < col; j++){
        cout << *((s.p+i)+j) << " ";
        }
        cout << endl;
    }
    return os;
};

int main(){

    SafeMatrix<int> b(3, 5);
    b[2][0] = 3;
    cout << b[2][0] <<endl;
    int counter = 0;
    for (int i = 0; i<3; i++)
        for (int j = 0; j < 5; j++)
            b[i][j] = ++counter;
    cout << "printing b the first time" <<endl;
    cout << b << endl;
    cout << "printing using []" << endl;
    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 5; j++){
            cout << b[i][j] << " ";
        }
        cout << endl;
    }
}

```

The errors I'm getting are kinda crazy, but here they are:

```
error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class SafeMatrix<int>)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@V?$SafeMatrix@H@@@Z) referenced in function _main    D:\OneDrive\VS\SafeMatrix\matrix.obj    SafeMatrix

```

and

```
error LNK1120: 1 unresolved externals   D:\OneDrive\VS\SafeMatrix\Debug\SafeMatrix.exe  1   1   SafeMatrix

```

and this warning:

```
Warning 1   warning C4150: deletion of pointer to incomplete type 'T'; no destructor called d:\onedrive\vs\safematrix\matrix.cpp    82  1   SafeMatrix

```

No idea what these mean.