Can you please see where i am going wrong in the erase function

you need to set , toBeDeleted->next=NULL, before deleting that value, because if you don’t then destructor will delete the entire linked list starting from this node .

correct code :-

void erase(string key){
    int idx = hashFunc(key);
    Node<T>* temp = table[idx];
    Node<T>* prev = NULL;

    while(temp != NULL){
        if(temp->key == key){
            if(prev){
                prev->next = temp->next;
            }
            else{
                table[idx] = temp->next;
            }
            temp->next = NULL;
            delete temp;
            return ;
        }
        prev = temp;
        temp = temp->next;
    }
}