I know this has been asked many times and answered many times, but I am still very confused.
I have plenty of knowledge of Java and I am now trying to pick up the low level stuff that I missed out from C++ such as memory allocation, pointers ,etc.
Below, I am trying to create my own linked list from scratch. I am trying to create a list within a for loop. I would like to destory, set to null, set to 0, something with the object myNode. (If there is an easier way, I still would like to know how to do this)
I have tried creating a dynamic bit of memory for it with the keyword new then setting it to null, 0, or using delete or free().
I keep getting errors such as non-|value assignment, operator= not assigned.
Can anyone give me some advice or at least try and explain it to me?
Thank you in advanced. Your help is much appreciated.
In C++ (unlike Java) NULL == 0, that's it. Because a pointer is pointing to a memory location, it contains an unsigned int. All memory locations are greater then 0 so pointing to memory at 0 means it's not pointing to valid memory. In Java, a Node would actually be a reference and so setting it to null means it's not referencing anything. In C++ a Node is an object, not a reference. That's why when you use the = operator you actually just call a method in the Node class that by default is (for the most part) equivalent to calling Object.clone() in Java.
I am still having a hard time understanding. I have set all my Node objects to just pointers. But now I have an error that says "cannot convert Node** to Node* at the bold statement below.
(*temp).pNext = &myNode;
That doesn't make sense to me. I am taking the data of temp and using its pointer of pNext and making it equal to the address of myNode. Shouldn't that work. Updated main is below.
int main()
{
int nodeNumber;
int thisData;
Node *myNode;
Node *temp;
Node *head;
cout<<"How many nodes?";
cin>>nodeNumber;
for(int a=0; a<nodeNumber; a++)
{
cout<<"Enter data for " << a << ": ";
cin>>thisData;