Hi,
I want to used shared_ptr here instead of raw pointers. How can the following code be changed to use shared_ptr or shared_array?
Code:
#define MAX_COLS 1000
MyClass
{
private:
int **m_value;
...
...
public:
Myclass()
{
m_value = new int *[MAX_COLS];
for(int count = 0; count < MAX_COLS; count++ )
{
m_value[count] = NULL;
}
}
~MyClass();
{
if(m_value)
{
for(int i = 0; i < MAX_COLS ; i++)
{
delete [](m_value[i]);
}
delete []m_value;
m_value = NULL;
}
}
void insert(index, int* data);
{
//do all the preliminary checks like bounds, null check
m_value[index] = data;
}
void processData()
{
for(int count = 0; count < MAX_COLS; count++ )
{
int *data = m_value[count];
//Write the data to a file or do something with it
}
}
//other members
};