This is for homework assignments, so there are explanations (and not direct codes) that I need.
We have recently learned about Copy Constructor / Assignment = Operators and such. In our handout we found our professor in the handout that if you want deep copy pointers, then you have to define them and copy the values directly
Example: (from handout)
class intCellFixed {public: IntCellFixed (int initialValue = 0) {stored value = new int (initial value); } // v this bit here V Intelligencia (Constellation and Source) {stored value = new int (); * Stored value = * source.storedValue; } // ^ here this bit ^ (...) private: int * storedValue; };
It makes sense to me that you have an indicator, and you want to believe that value, from which you will be equal to the value of the pointer you are copying . So you can do this to change that value at that address on which he points out, and I do not know it makes sense to me.
So when we went to experiment, in the laboratory, I tried the same way, but instead of linked lists instead of just an indicator even with the help of TA (TA Looked at my code and until the "right" thing until it was right), it still does not work and gave me just a seamfault. I did not get the chance to ask what the code was really, and the solution has not been posted yet.
We are doing almost the same thing in our homework. Here is the structure of our node (in a binary search tree):
Structure node {int data; integer number; Node * left; Node * true; }; I have this bit of code: BinarySearchTree :: insert (node * node, node * parent, int value) function in my zero: If (node == faucet) {node = new node (); * Node-> Data = value; * Node-> Count = 1; Node-> Left = null; Node-> Right = null; }
When I try to do this, even then, it gives me an error: invalid type logic ('int') of invalid '*'. When I close *, it runs fine, but does not actually save the node's data outside the insert function. (Ie: when attempting to insert multiple values, it always starts with an empty tree, even then it has been estimated that I have already put the price).
As far as I understand it, I will need to define the node because I do not want to know which points it to change, I want to know what will happen to the address to change .
Do I have completely misunderstanding / how to dereference? If I am, can anyone explain to me when I need it, and why do not I want it in this matter? Or, if this is a syntax error, can someone tell me what the syntax should be?
Comments
Post a Comment