title: C++ Calling a function from the header file in the main
body: <p>I'm writing an integral calculator. I'm trying to get the main.cpp file to read in the functions from the functions class which is in the functions.h.cpp files. I have a function defined as the following for the easy case:</p>
  
  <pre><code>double square(double aX)
   {
     return aX*aX;
   }
  </code></pre>
  
  <p>This function works when I include it in the main file, though it doesn't want to work when I try and call it from the main file when it's in the functions file. Here is the code that I have:</p>
  
  <p><code>Main.cpp</code> file:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "IntegralCalculator.h"
  #include "functions.h"
  
  using namespace std;
  
  int main()
    {
      IntegralCalculator Function(square);
      Function.print();
    }
  </code></pre>
  
  <p>As you can see, there is another class called <code>IntegralCalculator</code> which actually does the calculation of the integral, though nothing should be wrong with that as it works when the function definition is included in the main, and the function is passed as a parameter. The <code>functions.h</code> file is defined as the following:</p>
  
  <pre><code>#ifndef FUNCTIONS_H
  #define FUNCTIONS_H
  
  #include &lt;iostream&gt;
  #include &lt;cmath&gt;
  #include "IntegralCalculator.h"
  
  
  class functions : public IntegralCalculator
   {
    public:
     functions();
     double square(double aX);
  
   };
  
  #endif
  </code></pre>
  
  <p>and the <code>functions.cpp</code> file is defined as such:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cmath&gt;
  #include "functions.h"
  
  
  double functions::square(double aX)
   {
     return aX*aX;
   }
  </code></pre>
  
  <p>I know that as of right now I don't need the <code>&lt;cmath&gt;</code> library, though I'm going to need it for more complicated functions when I add them.</p>
  
  <p>I have tried inheriting the functions class in the main, and I have tried creating a namespace for the functions class and defining the function, however none of these have worked. When I go to compile, I get the following error:</p>
  
  <p><code>Main.cpp: In function ‘int main()’:</code></p>
  
  <p><code>Main.cpp:9: error: ‘square’ was not declared in this scope</code></p>
  
  <p>If someone could please help me figure out this problem. This code that I'm trying to write is more advanced than my class has gone over, so I'm not sure how to fix it, though I want to write the program this way.</p>
  
  <p>Edit: In case you were curious, I am including the <code>functions.h</code> and <code>functions.cpp</code> files in the Makefile. I was getting the same error when I was trying to put the <code>square(double aX)</code> definition in the <code>IntegralCalculator</code> class as well.</p>