I have code below, it always has memory leak please help me.
Thanks,
Ankata
class ABCD
{
public:
ABCD(void);
~ABCD(void);
CString tem1;
CString tem2;
};
class CDE :
public ABCD
{
public:
CDE(void);
~CDE(void);
CString tem;
};
void main()
{
CList<ABCD*> m;
CDE *a = new CDE();
a->tem1 = "AAA";
a->tem2 ="BBB";
a->tem ="CCC";
m.AddTail(a);
ABCD *b = m.GetTail();
delete b;
}
Your destructor for class ABCD is not virtual so by casting the pointer to base class type, it will not call the destructor of the derived one thus not freeing memory allocated in CDE.