The problem I am having is that when my class CLimb runs its destructor, if member *parent is NULL I get an "Access violation writing location 0xcccccccc" error, after the destructor is called, but before the body is executed.
limb.h
class CLimb
{
public:
CLimb(void);
CLimb(CLimb *_parent);
~CLimb(void);
float cut;
float bone;
float resistance;
CLimb *parent;
};
limb.cpp
#include "limb.h"
CLimb::CLimb(void) :
cut(0),
bone(0),
resistance(0)
{
parent = NULL;
}
CLimb::CLimb(CLimb *_parent) :
cut(0),
bone(0),
resistance(0)
{
parent = _parent;
}
CLimb::~CLimb(void)
{
}
I was also wondering if I had 2 instances, limb01 and limb02, where limb02 is the parent of limb01, if limb02 is deleted limb01->parent now points to an incorrect address. How would I resolve this? Would I have to add a *child pointer as well?
parentpointer in any of the provided code.CLimb's destructor as written doesn't touch that pointer at all.