尝试使用析构函数删除动态分配的矩阵时出错

如标题所述,我尝试使用析构函数删除动态分配的矩阵,并且出现以下错误:

oop.exe中的0x78D8DB1B(ucrtbased.dll)引发异常:0xC0000005:   访问冲突读取位置0xDDDDDDCD。

这是我尝试运行的代码。

    #include <iostream>
    using namespace std;

     template<class T>
    class Matrice
    {
    private:
        int marime;
        T** matrice;
    public:
        Matrice(int marime);
        ~Matrice();
        friend istream& operator>>(istream& in,Matrice<T>& mat) {
            for (int i = 0; i < mat.marime; i++) {
                for (int j = 0; j < mat.marime; j++) {
                    cout << "Matrice[" << i << "][" << j << "]: ";
                    in >> mat.matrice[i][j];
                }
            }
            return in;
        }
        friend ostream& operator<<(ostream& out,Matrice<T> mat) {
            for (int i = 0; i < mat.marime; i++) {
                cout << endl;
                for (int j = 0; j < mat.marime; j++) {
                    out << mat.matrice[i][j]<<" ";
                }
            }
            return out;
        }
    };

    template<class T>
    Matrice<T>::Matrice(int marime) {
        this->marime = marime;
        matrice = new T * [marime];
        for (int i = 0; i < marime; i++) {
            matrice[i] = new T[marime];
        }
    }
    template<class T>
    Matrice<T>::~Matrice() {
        for (int i = 0; i < marime; i++) {
            delete[] matrice[i]; //Here is where i get the error.
        }
        delete[] matrice;
    }

int main()
{
    Matrice<int> test(3);
    cin >> test;
    cout << test;
}