B
Bushido Hacks
I think this message got lost the first time I sent it, so I'm
reposting it.
I need a little help with Destructors.
Suppose I created a multidimmensional array in a Base class that was
also accessable in a Derived class, would I need to delete the array
in the Derived class if I declared my destructors as virtual?
class Base
{
public:
...
virtual ~Base();
protected:
int m; // rows
int n; // cols
double** p;
};
class Derived : public Base
{
public:
...
virtual ~Derived();
};
Base::~Base()
{
for(int i = 0; i < m; i++){delete[] p;};
delete[] p;
};
Derived::~Derived(){
// Should these lines be here?
for(int i = 0; i < m; i++){delete[] p;};
delete[] p;
};
reposting it.
I need a little help with Destructors.
Suppose I created a multidimmensional array in a Base class that was
also accessable in a Derived class, would I need to delete the array
in the Derived class if I declared my destructors as virtual?
class Base
{
public:
...
virtual ~Base();
protected:
int m; // rows
int n; // cols
double** p;
};
class Derived : public Base
{
public:
...
virtual ~Derived();
};
Base::~Base()
{
for(int i = 0; i < m; i++){delete[] p;};
delete[] p;
};
Derived::~Derived(){
// Should these lines be here?
for(int i = 0; i < m; i++){delete[] p;};
delete[] p;
};