Memory Leak why
there is memory leak in this program why and how i'll fix it i think i have to make the base class distructor a virtual distructor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
class Base
{
char * p;
public:
Base() { p = new char[10]; }
~Base() { delete [] p; }
};
class Derived : public Base
{
char * q;
public:
Derived() { q = new char[20]; }
~Derived() { delete [] q; }
};
void foo()
{
Base* p = new Derived();
delete p;
}
|
make the distructor as virtual..
Last edited on
Topic archived. No new replies allowed.