I have a networking framework that I am writing (Trying to implement reliable layer over UDP). I have this receive function that accepts a pointer to a packet object. The network framework then does a whole load of stuff to receive a packet, and sets the value of the packet pointer to this packet. But this happens a few functions deep. So what I am essentially wondering is, why this doesn’t something like this work for me: (very basic example to show you what i mean)
void Main()
{
int* intPointer = NULL;
SomeFunction(intPointer);
//intPointer is still null?
}
void SomeFunction(int* outInt)
{
SomeOtherFunction(outInt);
}
void SomeOtherFunction(int* outInt)
{
outInt = new int(5);
}
SomeOtherFunctionis passed a pointer by value, so the assignment only changes the local copy of the passed address.To make this work, pass the pointer by reference:
Having said that, is there something wrong with using a return value?
[ Update following comment. ]
Well, if you have a return value indicating the status, presumably indicating whether or not the integer has been read, then what you really want is (using
boolas a placeholder for your specific status):