I see I can't edit my las replay so I am writing in a new one.
I want to emphasize the problem so here is a piece of code of the idea:
As you can see, problem is, I change my nil which should not be changed at all.Code:// say somewhere in the code I have this assignment: RBNode* y; y = some_other_node_pointer; // when some_other_node_pointer points to nil! // sure now y points to our static nil instance... // then there might be some thing like that: y->right = x; // x is also RBNode* and isn't nil
Fix me if I am wrong but it seems to me that the best way to deal with it is to do something like that:
Code:RBNode* y; y .operator=(some_other_node_pointer); y->right.oprator = (x); // operator = will make sure the argument isn't nil. If it's nil it will allocate another instance and will initialize it as I want..