Interview Question
Country: United States
m_pData is not initialized when constructing an Array object of size 0, so it will contain a random address. Upon destruction, the destructor will most likely find m_pData != NULL and try to delete that memory. Crash.
In other words, this will crash as soon as the program exits the block:
{
Array a(0);
}
There will be a problem if the class object is passed by value
- Anonymous February 26, 2012should use smart pointer, not the regular one, or should define copy constructor and assignment operator (use deep copy, not shallow copy)