title: C++ Best way to handle division by zero
body: <p>I'm writing a C++ class that stores some double values in a vector (called mpValues) and calculates their average. When constructed, the value array is empty, so performing this calculation would return 0.0/0.0. </p>
  
  <p>I decided that asking for the mean of zero values is a error. Therefore, it would be best to return NaN and display an error message, so that the user is made aware of that problem.
  The code looks like this:</p>
  
  <pre><code>double Average::CalculateAverage() const
  {
      if(mpValues-&gt;size() == 0){
          std::cerr &lt;&lt; "Instance of Average at: " &lt;&lt; this &lt;&lt; " contains no values.\n"
                    &lt;&lt; "In this case the arithmetic mean is defined as NaN." &lt;&lt;std::endl;
  
          return 0.0/0.0;
      }
      else{
          ...calculate the arithmetic mean
      }
  }
  </code></pre>
  
  <p>Is this a sensible approach, or do you have better suggestions? Usually, I wouldn't be so fussy, but this is a test for a job offer so I'd like to avoid bad decisions. </p>
  
  <p>Thanks in advance!</p>