Destructor for the Deque class question.

I have to write a deque class for school and I am having a problem with the destructor. Each block of the deque holds a vector which is from the class block.

Deque constructor:
1
2
3
4
5
6
7
8
9
template<typename generic>
Deque<generic>::Deque()
{
	m_size = 0;
	m_blocks = 1;
	m_block_size = 3;
	m_data = new Block<generic>*[m_blocks];
	m_data[0] = new Block<generic>;
}


Deque destructor that doesn't fully work:
1
2
3
4
5
template<typename generic>
Deque<generic>::~Deque()
{
	delete [] m_data;
}


Block constructor:
1
2
3
4
5
6
7
8
template<typename generic>
Block<generic>::Block()
{
	m_size = 0;
	m_max_size = 3;
	m_data = new generic[m_max_size];
	m_front = m_max_size-1;
}


Block destructor:
1
2
3
4
5
template<typename generic>
Block<generic>::~Block()
{
	delete [] m_data;
}


The block desturctor works but the Deque destructor has data loss when I run it.
I'm pretty sure it's because it's not destructing the Block inside the Deque but I'm
not for sure. Any help will be appreciated.
Yes, that's right. You need to iterate over the m_data array and delete each element.
Ok I got it now, I tried that but I guess I just miss typed something earlier. Thanks :)
Topic archived. No new replies allowed.