I have a sparse matrix class with rows and columns. The rows integer is used to initialize a numbers of LinkedList in a dynamic array.
template<class T>
SM<T>::SM(int rows, int columns)
{
    this->rows = rows;
    this->columns = columns;
    this->rowList = new LinkedList<T>[rows];
    cout << "Going to create a sparse matrix of dimensions " << this->rows << "-" << this->columns << endl;
}
I also have this copy constructor to be used later on:
EDIT:
LinkedList copy constructor:
LinkedList(const LinkedList & other) {
    this->size = other.size;
    this->head = NULL;
    this->tail = NULL;
    NodeType<T> * current = other.head;
    while (current != NULL) {
        setValue(current->info, current->index);
        current = current->link;
    }
}
SparseMatrix copy constructor:
template<class T>
SM<T>::SM(const SM<T> & other)
{
    this->rows = other.rows;
    this->columns = other.columns;
    this->rowList = new LinkedList<T>[this->rows];
    for (int i = 0; i < this->rows; i++)
    {
        rowList[i] = other.rowList[i];
    }
}
This is my LinkedList destructor and SparseMatrix destrcutor:
~LinkedList() {
    cout << "Going to delete all " << size << " elements of the list." << endl;
    NodeType<T> * current = head;
    while (current != NULL) {
        current = current->link;
        delete head;
        head = current;
    }
}
template<class T>
SM<T>::~SM()
{
    cout << "Deleting sm" << endl;
    delete [] rowList;
    rowList = NULL;
}
However, when I'm done with the code. I get a destructor error.
Here is my main() :
SM<int> sm(rows, columns);
SM<int> sm2(rows, columns);
SM<int> sm3 = sm2;
This is the error:
_CrtIsValidHeapPointer
I'm new to C++ and I have really no idea what's wrong with my code. Any help is deeply appreciated.
 
     
     
    
>`. Then you would not need to write any special functions of your own, saving much time in both coding and debugging