Help with delete of User object
Hi, I am rather new to C++ and an invalid exception has occurs in my
system which I have absolutely no idea as to why it happens. Please
help! Thank you.
I have created a method which takes in pObject and assigned to m_pObj
which is a CGLObj pointer variable in the CGLTest class.
CGLTest::~CGLTest() //destructor
{
if(m_pObj) {
delete m_pObj;
m_pObj = NULL;
}
}
void CGLTest::SetObj(CGLObj *pObject)
{
m_pObj = pObject;
}
And the class that calls the SetObj class is as follows
CGLTesterView::~CGLTesterView()
{
if(m_pObj[0]) delete m_pObj[0];
}
void CGLTesterView::Scene()
{
CGLObj *pObj = m_pObj[nObj];
if(pObj)
{
m_model.SetObj(pObj);
m_model.Render();
}
//should I include a delete pObj here??
}
Upon closing my dialog window, an exception will occur as if when I
delete m_pObj in the CGLTest class, it deletes the CGLTesterView
m_pObj. But I am not sure as to how to solve this exception. As I am
required to delete the pointer used.
Another qns: For the CGLTest::SetObj class where I have written
m_pObj = pObject is it the same as the following 3 lines of codes??
if(m_pObj) { free(m_pObj); m_pObj = NULL; }
m_pObj = (CGL3DObj *) malloc(sizeof(CGL3DObj));
memcpy(m_pObj, pObject, sizeof(CGL3DObj)); //copied the object
Any help is greatly appreciated.. :)