how to Clean up(destructor) a dynamic Array of pointers??

Posted by Ahmed Sharara on Stack Overflow See other posts from Stack Overflow or by Ahmed Sharara
Published on 2010-05-21T14:03:14Z Indexed on 2010/05/21 14:10 UTC
Read the original article Hit count: 213

Filed under:
|
|
|
|

Is that Destructor is enough or do I have to iterate to delete the new nodes??

#include "stdafx.h"  
#include<iostream>  
using namespace std;  
struct node{  
    int row;  
    int col;  
    int value;  
    node* next_in_row;  
    node* next_in_col;  
};  

class MultiLinkedListSparseArray {  
private:  
    char *logfile;  
    node** rowPtr;  
    node** colPtr; // used in constructor  
    node* find_node(node* out);  
    node* ins_node(node* ins,int col);  
    node* in_node(node* ins,node* z);  
    node* get(node* in,int row,int col);  
    bool exist(node* so,int row,int col);  
    //add anything you need
public:  
    MultiLinkedListSparseArray(int rows, int cols);  
    ~MultiLinkedListSparseArray();  
    void setCell(int row, int col, int value);  
    int getCell(int row, int col);  
    void display();  
    void log(char *s);  
    void dump();  
};  

MultiLinkedListSparseArray::MultiLinkedListSparseArray(int rows,int cols){  
    rowPtr=new node* [rows+1];  
    colPtr=new node* [cols+1];  
    for(int n=0;n<=rows;n++)  
        rowPtr[n]=NULL;  
    for(int i=0;i<=cols;i++)  
        colPtr[i]=NULL;  
}  

MultiLinkedListSparseArray::~MultiLinkedListSparseArray(){ // is that destructor enough??  
    cout<<"array is deleted"<<endl;  
    delete [] rowPtr;  
    delete [] colPtr;  
}  

© Stack Overflow or respective owner

Related posts about c++

Related posts about dynamic-arrays