Hey guys sorry about the influx of questions today,this is my third I have been studying all day
anyway one thing that has always kind of confused me is when we return references,now I know passing by reference is pretty much passing the memory address of the object or type itself into a function but returning it seems to be giving me some issues
in my code below I have implemented a doubly linked list,the focus is on the overloaded pre and post fix operators
how come this code won't compile
1 2 3 4 5 6 7
Node& operator++(){
now = now->next;
return now;
}
now is a pointer to a node so it stores the memory address of a node
shouldn't this be valid since we are returning an address of a node?
1 2 3 4 5 6 7
Node& operator++(){
now = now->next;
return *now;
}
this code seems to work fine but here we are returning the object itself right? I thought we should be just returning the address?
* A reference to the pointer 'now', through which the caller can modify the value of 'now' of the List, if they so please.
* A reference to the Node that the pointer 'now' points to.
What if the 'now' did point to the last Node before the ++ ? You would return a reference to NULL.
* Pointer to the same node as the 'now' points to.