I have a class that has a pointer to an array of a generic type T.
I created a copy constructor with the following code:
The issue with this is m_array has the value 0xcccccccc. So it hasn't been initialized. However, 0xcccccccc does not mean NULL, so it goes into the block. Now it's deleting an array that is not initialized still. I think this is due to MS's debugger where 0xcccccccc is suppose "to help you". Any idea how to avoid or work around this? Thanks.Code:// Release the old array. if (m_array != NULL) { delete [] m_array; m_array = NULL; }
Since this may come up, it's a copy constructor. So I can do this: X x(a); or X x = a;
So I can't just set m_array to NULL in the beginning because it may be already allocated. So I'm facing an array that may or may not be initialized...
Here's how it's initializing:
MyOb<int> b = a;
So it calls the copy constructor first here.



LinkBack URL
About LinkBacks



CornedBee