title: "Candidate function not viable" from g++/gcc compiler. What is wrong here?
body: <p>I'm trying to compile my main.cpp, but I keep getting this error for two hours now. The issue here is to pass a function as a parameter but I think I'm doing something wrong. The compiler says it cannot find the function, but I included "newt_rhap(params)" in the "functions.h" already.</p>
  
  <p>I did the returnType (*functionName)(paramType), but I may have skipped something here. The code of my friends doesn't need the recently mentioned syntax. What is wrong here?</p>
  
  <p>I tried using both -std=c++11 and -std=c++98. The gcc/g++ compiler came from my Xcode command line tools.</p>
  
  <pre><code>g++ (or gcc) -std=c++98(or 11) main.cpp -o main.out
  </code></pre>
  
  <p>There was no difference in error.</p>
  
  <pre><code>**error: no matching function for call to 'newt_rhap'**
  
  ./functions.h:5:8: note: candidate function not viable: no known conversion from 'double' to
        'double (*)(double)' for 1st argument
  
  double newt_rhap(double deriv(double), double eq(double), double guess);
  </code></pre>
  
  <p>Here is the code.</p>
  
  <pre><code>// main.cpp
  #include &lt;cmath&gt;
  #include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  #include "functions.h"
  
  using namespace std;
  
  
  // function declarations
  // =============
  // void test(double d);
  // =============
  
  int main(int argc, char const *argv[])
  {
      //
      // stuff here excluded for brevity
      //
  
      // =============
      do
      {
          // line with error
          guess = newt_rhap(eq1(guess),d1(guess),guess);
  
          // more brevity
  
      } while(nSig &lt;= min_nSig);
      // =============
  
      cout &lt;&lt; "Root found: " &lt;&lt; guess &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>
  
  <p>Then functions.h and functions.cpp, respectively</p>
  
  <pre><code>// functions.h
  #ifndef FUNCTIONS_H_INCLUDED
  #define FUNCTIONS_H_INCLUDED
  
  // ===========
  double newt_rhap(double deriv(double), double eq(double), double guess);
  // ===========
  
  
  // ===========
  double eq1(double x);
  double d1(double x);
  // ===========
  
  
  #endif
  
  // functions.cpp
  #include &lt;cmath&gt;
  #include "functions.h"
  
  using namespace std;
  
  // ===========
  double newt_rhap(double (*eq)(double ) , double (*deriv)(double ), double guess)
  {
      return guess - (eq(guess)/deriv(guess));
  }
  // ===========
  
  // ===========
  double eq1(double x)
  {
      return exp(-x) - x;
  }
  
  double d1(double x)
  {
      return -exp(-x) - 1;
  }
  </code></pre>