title: Returning multiple values from a C++ function
body: <p>Is there a preferred way to return multiple values from a C++ function?  For example, imagine a function that divides two integers and returns both the quotient and the remainder.  One way I commonly see is to use reference parameters:</p>
  
  <pre><code>void divide(int dividend, int divisor, int&amp; quotient, int&amp; remainder);
  </code></pre>
  
  <p>A variation is to return one value and pass the other through a reference parameter:</p>
  
  <pre><code>int divide(int dividend, int divisor, int&amp; remainder);
  </code></pre>
  
  <p>Another way would be to declare a struct to contain all of the results and return that:</p>
  
  <pre><code>struct divide_result {
      int quotient;
      int remainder;
  };
  
  divide_result divide(int dividend, int divisor);
  </code></pre>
  
  <p>Is one of these ways generally preferred, or are there other suggestions?</p>
  
  <p>Edit: In the real-world code, there may be more than two results.  They may also be of different types.</p>