Hello All,

I have encountered a problem in CArray which
I don't know the reason ..


// In my header file, i have a struct declaration
// File.h
typedef struct _tagStruct
{
int nCounter;
CString strName;
} REC_STRUCT;

CArray < REC_STRUCT*, REC_STRUCT* > m_Array;

// Then, in the implementation file
// File.cpp

void File::ArrayDemo()
{
m_Array.SetSize( 2 );
REC_STRUCT * p = NULL;

for ( int i=0; i<2; i++ )
{
p = new REC_STRUCT;
p->nCounter = 100; // Assign Values
p->strName = "HELLO";
m_Array->SetAt( i,p );

// Here, if I won't delete p, it will cause a
// memory leak. But if I will delete p, refer
// below :
delete p;
}

// Here if p is deleted, data in the array is lost !!
for ( int j=0; j<2; j++ )
{
REC_STRUCT * p1 = m_Array.GetAt( j );
// p1->nCounter has now a NEGATIVE value
// p1->strName is EQUAL to ""
}
}




I would appreciate if somebody can tell the reason
why CArray behaves like the one above!


Thank you very much!