I am facing a problem with a CArray. I have a class member of type CArray<MyType, MyType&> m_MyArray;
When the object is destroyed, of course the destructor of CArray<MyType, MyType&> is called.

Here is the destructor:

template<class TYPE, class ARG_TYPE>
CArray<TYPE, ARG_TYPE>::~CArray()
{
	ASSERT_VALID(this);

	if (m_pData != NULL)
	{
		for( int i = 0; i < m_nSize; i++ )
			(m_pData + i)->~TYPE();
		delete[] (BYTE*)m_pData;
	}
}

The debugger shows my m_pData to be 0X00000005.
As we can see from the code above, delete[] is called on this pointer because it is not NULL. The delete[] calls delete, which calls _free_dbg(), which calls CheckBytes(), where the pointer is passed already as 0X00000000 (bad ptr). On attempt to dereference this pointer ( if (*pb++ != bCheck)), a crash happens.
Can somebody help me solve this problem, please?
Thanks.

CArray<> is an MFC class, right? The problem is almost surely going to be in your code, not the code of CArray<>. Can you post a small program that has the same error so that everyone can see how you are using the class?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.