title: Function argument type followed by *&
body: <p>I have some code written by someone else in which some functions take arguments whose data types are followed by a *&amp;. I'm used to functions taking one or the other, e.g. taking a "double *" or a "double &amp;" but not both. It would have thought they would just cancel out. </p>
  
  <p>Here's an example, and this is all from their code which supposedly works:</p>
  
  <p>In a header file there's a function declared as:</p>
  
  <pre><code>void someClass::foo(const unsigned int*&amp; ubuff);
  </code></pre>
  
  <p>Then in my main file, there's a pointer to some UINTs declared and initialized as:</p>
  
  <pre><code>unsigned int* pbuff = new UINT[n];
  </code></pre>
  
  <p>Then, the function someClass::foo is called as:</p>
  
  <pre><code>foo(pbuff);
  </code></pre>
  
  <p>When I compile, I get the error "cannot convert parameter 1 from 'unsigned int *' to 'const unsigned int *&amp;'". If I change my function call to the following, it compiles ok:</p>
  
  <pre><code>foo((const unsigned int *&amp;)(pbuff));
  </code></pre>
  
  <p>So, my questions are:</p>
  
  <ol>
  <li><p>What is the purpose of the *&amp;? I.e., how is that different from * or &amp; by themselves, and why do they not just cancel themselves out? And what does that make the function foo expect? An address? A value? The address of an address? It's confusing.</p></li>
  <li><p>Is the fix of simply casting a "unsigned int*" to a "const unsigned int*&amp;" ok or do I need to do something else?</p></li>
  </ol>
  
  <p>Just another quick example, and this is from completely within a cpp file distributed by someone else, so I assume this compiled for them. They have a function call as </p>
  
  <pre><code>klabels = new int[sz];
  EnforceLabelConnectivity(klabels, m_width, m_height, nlabels, numlabels, double(sz)/double(STEP*STEP));
  </code></pre>
  
  <p>When I try to build, I get an error "'SLIC::EnforceLabelConnectivity' : cannot convert parameter 1 from 'int *' to 'const int *&amp;'". </p>
  
  <p>Thanks as always. </p>