I searched for an answer to this question, but did not come across a case like mine.
Having the following code:
A
{
private:
SomeObject** _array;
public:
A(int n) {
_array = new SomeObject*[n];
}
virtual ~A(){
delete[] _array;
}
}
As you can see _array is a pointer to an array of pointers, pointing at objects(SomeObject). Is the destructor in the code correct? As far as i understand, "delete []" calls the destructor of each element in the array. And as this is an array of pointers, simply calling "delete []" is not correct. In my opinion, the correct solution is to 1)iterate over the array and delete each element, then 2)call "delete [] _array".
Thank you very much in advance!