1.
Will my deconstructor delete the object `next` and `previous` or just the pointer? I want it only to delete the pointer.
2.
let's say i have
1 2
ofxDTangibleBase a;
ofxDTangibleBase b;
and `a.next` points to `b` and `b.previous` points to `a`. If i deconstruct `a`.
Will `b.previous` point to a NULL or does it point to the location in memmory where `a` was before?
3.
My program stops on the last line in the deconstructor with `EXC_BAD_ACCESS`.
What could be a possible reason for this.
delete deletes the object and does not change where the pointer points to.
Normally, when an objects holds a pointer to another object, and that other object dies, the pointer still points to the memory location the object occupied (not set to null magically).
But, I assume that if b.previous points to a, then a.next points to b. So when you loose a (it goes out of scope or is deleted) it fires destructor that in turn deletes b, and b deletes its next - c and so on. Entire chain is destroyed. And since the destruction goes both ways it inevitably reaches the point when someone orders to delete somebody who just deleted that someone ;) And when that happens, the program crashes.
What you really need to do in destructor is set object's neighbour's next and previous pointers to null, not delete them.
Pointer DO NOT GET deleted. They hold addresses, like visit cards. When you call delete you are telling the compiler: "Here, look at that visit card. Go under that address and kill whoever lives there". The compiler kills the object, and you keep your visit card. It still has the same address printed on, so you should be carefull not to tell compiler again to go and kill whoever lives there, because at that time there will be someone else, and you don't even know who. Basically, the visit cards gets useless, or even dangerous untill you correct the information printed on it.
So just to be sure, after you call delete, you take a black marker and cross out the address from visit card, just to be sure no one gets killed accidentally.
Or in other words, assign null to the pointer.
Pointers themselves do not need to be deleted. Remember, as soon as they go out of scope, they dissapear.
<offtop> Silvestar, you barbarian! Some peaople just want to keep things civil, and not blindly destroy anything around. I for example would call that assassin (as per example above);)
</offtop>