Ok well that was a dumb mistake but I agree with you about the const but my teacher gave me the .h file and when he test it with his test code it could mess up and I would lose points.
Now it runs but doesn't pass the test. What is wrong with this test?
What do "clear()" and "push_back()" do? I think the problem might be with how your copy ctor allocates memory, then just immediately clears() it by calling operator =. It might be easier just to have your copy ctor do this:
1 2 3 4
Deque<generic>::Deque(Deque<generic>& d) {
//set up any state variables that need to be set before you call operator =
*this = d;
}
template<typename generic>
void Deque<generic>::push_back(generic x)
{
if(m_data[m_blocks-1] -> bfull()) // bfull() checks if the back of the block is full
{
Block<generic>** temp = m_data;
m_data = new Block<generic>*[++m_blocks];
m_data[m_blocks-1] = new Block<generic>(m_block_size);
for(int i = 0; i < m_blocks-1; i++)
{
m_data[i] = temp[i];
}
delete [] temp;
}
m_data[m_blocks-1] -> push_back(x);
m_size++;
}
The = operator has to clear it because that is not the only place it is used. It can be used other places where it might already have stuff stored in it.
Ok I figured it out, I was making it more complecated than it really was. I just needed to initalize it as an empty Deque with size 0 and go from there. Thanks for the help anyway. :)