|
-
January 3rd, 2006, 12:47 PM
#1
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.
-
January 3rd, 2006, 12:52 PM
#2
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.
-
January 3rd, 2006, 12:54 PM
#3
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!
-
January 3rd, 2006, 01:40 PM
#4
Re: me not understanding pointer's
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|