title: How can I add an output parameter to a function without breaking existing code?
body: <p>I am assuming that the function already has a return value so that cannot be added.</p>
  
  <p>What I came up with to solve this problem is to add extra pointer parameters which default to nullptr.</p>
  
  <p>Before:</p>
  
  <pre><code>bool fun(double a, std::vector&lt;std::randomexample&gt; const &amp; b)
  </code></pre>
  
  <p>After:</p>
  
  <pre><code>bool fun(double a, std::vector&lt;std::randomexample&gt; const &amp; b, int* extraoutput = nullptr)
  </code></pre>
  
  <p>and use it like this</p>
  
  <pre><code>if(extraoutput)
    *extraoutput = whatever;
  </code></pre>
  
  <p>But that's just what I came up with.
  I would like to know if there is a better way to do this. Note that "whatever" is already in the function.</p>