me not understanding pointer's
// call function
BYTE *pData;
Func( pData );
// pData no null.
// Function
Func( BYTE *pData )
{
pData = new BYTE[some_data_length];
memcpy( pData, some_data, some_data_length );
}
Why after the function returns is pData nullified?
The pointer is passed in fine, and the memory is allocated OK.
I know its elementary, but I seem to missing something obvious...
Thanks.
Re: me not understanding pointer's
because pData is a pointer that is local to your function.
When you call new in your function this is for the local copy only.
Given that this is C++ code (you use new) then use vector (or basic_string).
But if you have to use pointers, then
Code:
Func( BYTE * & pData )
will fix your problem.
Re: me not understanding pointer's
Thanks. I dont know whats wrong with me today - I seem to have forgotten everything over the xmas break! :(
Re: me not understanding pointer's