I have a structure with two constructor that has a byte* member as following :
struct structA
{
byte* pData; int nLength;
structA()
{
pData = NULL; nLength = 0;
}
structA(int nLen)
{
pData = new byte[nLen]; nLength = nLen;
}
~structA()
{
delete[] pData;
}
}
Another structure namely structB has a list of structA:
struct structB
{
CList <structA, structA&> AList;
}
Now i create an object of structA with parameter 10 as input and add it to an object of structB:
//start of scope
structA osA(10);
structB osB;
osB.AList.AddTail(osA);
//end of scope
The problem is that when the program exit from the scope, destructure of structA is called 2 times and program crashes.
what is the problem and why it occurs? any help is apperciated