what will be the real memory releasing behaviour of following code snippet. Will all memory release properly? -
Code:Class A { }; Class B : public A { }; main() { A *ptr = new B; A *ptr1 = new B[10]; delete ptr; delete [] ptr1; }
what will be the real memory releasing behaviour of following code snippet. Will all memory release properly? -
Code:Class A { }; Class B : public A { }; main() { A *ptr = new B; A *ptr1 = new B[10]; delete ptr; delete [] ptr1; }
Both the delete and the delete[] result in undefined behaviour since A does not have a virtual destructor, yet you attempt to destroy an object (or array thereof) of B through a pointer to A.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)