title: Getting: error C2668: 'sqrt' : ambiguous call to overloaded function
body: <p>Trying to build the source code below from an example given in a textbook.
  I'm using visual studio 2008.</p>
  
  <p>The compiler doesn't seem to know what to do with sieve:</p>
  
  <pre><code>1&gt;------ Rebuild All started: Project: fig21.40, Configuration: Debug Win32 ------
  1&gt;Deleting intermediate and output files for project 'fig21.40', configuration        'Debug|Win32'
  1&gt;Compiling...
  1&gt;fig21_40.cpp
  1&gt;c:\users\ocuk\documents\c++\chapter 21\fig21.40\fig21.40\fig21_40.cpp(27) : error C2668: 'sqrt' : ambiguous call to overloaded function
  1&gt;        c:\program files (x86)\microsoft visual studio 9.0\vc\include\math.h(581): could be 'long double sqrt(long double)'
  1&gt;        c:\program files (x86)\microsoft visual studio 9.0\vc\include\math.h(533): or       'float sqrt(float)'
  1&gt;        c:\program files (x86)\microsoft visual studio 9.0\vc\include\math.h(128): or       'double sqrt(double)'
  1&gt;        while trying to match the argument list '(const int)'
  1&gt;Build log was saved at "file://c:\Users\ocuk\Documents\C++\Chapter 21\fig21.40\fig21.40\Debug\BuildLog.htm"
  1&gt;fig21.40 - 1 error(s), 0 warning(s)
  ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
  </code></pre>
  
  <p>code:</p>
  
  <pre><code>//Fig. 21.40: fig21_40.cpp
  //Using a bitset to demonstrate the Sieve of Eratosthenses
  
  #include &lt;iostream&gt;
  
  using std::cin;
  using std::cout;
  using std::endl;
  
  #include &lt;iomanip&gt;
  
  using std::setw;
  
  #include &lt;bitset&gt;   //bitset class definition
  #include &lt;cmath&gt;    //sqrt prototype
  
  int main()
  {
  const int size=1024;
  int value;
  std::bitset&lt;size&gt; sieve;
  
  sieve.flip();
  
  //perform Sieve of Eratosthenses
  int finalBit = sqrt( sieve.size() ) + 1;
  
  for(int i=2; i&lt;finalBit; ++i)
      if(sieve.test(i))
          for(int j=2*i; j&lt;size; j+=i)
              sieve.reset(j);
  
  cout &lt;&lt; "The prime numbers in the range 2 to 1023 are:\n";
  
  //display prime numbers in range 2-1023
  for(int k=2, counter=0; k&lt;size; ++k)
  
      if(sieve.test(k)){
          cout &lt;&lt;setw(5)&lt;&lt;k;
          if(++counter % 12 ==0)
              cout &lt;&lt; '\n';
      }//end outer if
  
  cout &lt;&lt; endl;
  
  //get value from user to determine whether value is prime
  cout &lt;&lt; "\nEnter a value from 1 to 1023(-1 to end): ";
  cin&gt;&gt;value;
  
  while(value != -1){
      if(sieve[value])
          cout &lt;&lt; value &lt;&lt; " is a prime number\n";
      else
          cout &lt;&lt; value &lt;&lt; " is not a prime number\n";
  
      cout &lt;&lt; "\nEnter a value from 2 to 1023 (-1 to end): ";
      cin &gt;&gt; value;
  }//end while
  
  
  
  return 0;
  }
  </code></pre>