CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #6
    Join Date
    May 2007
    Location
    Scotland
    Posts
    1,164

    Re: Help - What does litem*& list stands for?

    In addition to Russco's explanation, if you wanted the C equivalent of

    Code:
    void set(int*& ptr)
    {
        ptr = assign_to_something();
    }
    then you would need to write

    Code:
    void set( int** ptr)
    {
        *ptr = assign_to_something();
    }
    which not only makes the function look slightly messier, but from an interface perspective, it is not obvious why you require int** ptr - a user may legitimately ask, is it because you want to modify the pointer or, is it that you require int** prt because you are expecting a pointer to an array of pointers? In addition, the caller needs to reference the pointer in the function call i.e.

    Code:
    int main()
    {
      int* ptr=0;
      
      set(&ptr);
    }
    The pass-by-referece mechanism that C++ offers is much clearer and leaves far less room for error:

    Code:
    void set(int*& ptr)
    {
        ptr = assign_to_something();
    }
    
    int main()
    {
      int* ptr=0;
      
      set(ptr);
    }
    Last edited by PredicateNormative; April 21st, 2010 at 09:19 AM.

Tags for this Thread

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