CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Posts
    133

    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.

  2. #2
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    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.

  3. #3
    Join Date
    Aug 2004
    Posts
    133

    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!

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: me not understanding pointer's

    See this FAQ.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured