title: C++ error: Call to non-constexpr function
body: <p>I am trying to compile the following C++ code (saved as example4.cpp)</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  constexpr double nth(double x, int n);//initialization
  
  int main()
  {
  double x=2;
  int n=5;
  nth(x,n);//Function call
  return 0;
  }
  
  
  constexpr double nth(double x, int n)   // function definition
  {
      double res = 1;
      int i = 0;
      while (i&lt;n) {   // while-loop: do while the condition is true
           res*=x;
           ++i;
      }
  cout &lt;&lt; res;
  cout &lt;&lt; endl;
      return res;
  }
  </code></pre>
  
  <p>This code is giving the following error:</p>
  
  <p>example4.cpp: In function ‘constexpr double nth(double, int)’:
  example4.cpp:24:9: error: call to non-constexpr function ‘std::basic_ostream&lt;_CharT, _Traits>::__ostream_type&amp; std::basic_ostream&lt;_CharT, _Traits>::operator&lt;&lt;(double) [with _CharT = char; _Traits = std::char_traits; std::basic_ostream&lt;_CharT, _Traits>::__ostream_type = std::basic_ostream]’
   cout &lt;&lt; res;</p>
  
  <p>Can anyone please suggest?</p>
  
  <p>Thank you.</p>