title: 'foo' was not declared in this scope c++
body: <p>I'm just learning c++ (first day looking at it since I took a 1 week summer camp years ago)</p>
  
  <p>I was converting a program I'm working on in Java to C++:</p>
  
  <pre><code>#ifndef ADD_H
  #define ADD_H
  #define _USE_MATH_DEFINES
  #include &lt;iostream&gt;
  #include &lt;math.h&gt;
  
  using namespace std;
  
  class Evaluatable {
  public:
    virtual double evaluate(double x);
  };
  
  class SkewNormalEvalutatable : Evaluatable{
  public:
    SkewNormalEvalutatable();
    double evaluate(double x){
      return 1 / sqrt(2 * M_PI) * pow(2.71828182845904523536, -x * x / 2);
    }
  };
  
  SkewNormalEvalutatable::SkewNormalEvalutatable()
  {
  }
  
  double getSkewNormal(double skewValue, double x)
  {
    SkewNormalEvalutatable e ();
    return 2 / sqrt(2 * M_PI) * pow(2.71828182845904523536, -x * x / 2) * integrate(-1000, skewValue * x, 10000, e);
  }
  
  // double normalDist(double x){
  //   return 1 / Math.sqrt(2 * Math.PI) * Math.pow(Math.E, -x * x / 2);
  // }
  
  double integrate (double start, double stop,
                                       int numSteps, 
                                       Evaluatable evalObj)
  {
    double stepSize = (stop - start) / (double)numSteps;
    start = start + stepSize / 2.0;
    return (stepSize * sum(start, stop, stepSize, evalObj));
  }
  
  double sum (double start, double stop,
                                 double stepSize,
                                 Evaluatable evalObj)
  {
    double sum = 0.0, current = start;
    while (current &lt;= stop) {
      sum += evalObj.evaluate(current);
      current += stepSize;
    }
    return(sum);
  }
  
  // int main()
  // {
  //   cout &lt;&lt; getSkewNormal(10.0, 0) &lt;&lt; endl;
  //   return 0;
  // }
  #endif
  </code></pre>
  
  <p>The errors were:</p>
  
  <pre><code>SkewNormal.h: In function 'double getSkewNormal(double, double)' :
  SkewNormal.h: 29: error: 'integrate' was not declared in this scope
  SkewNormal.h: In function 'double integrate(double, double, int, Evaluatable)':
  SkewNormal.h:41: error: 'sum' was not declared in this scope
  </code></pre>
  
  <p>Integrate and sum are both supposed to be functions</p>
  
  <p>Here is the Java code, more or less the same:</p>
  
  <pre><code>public static double negativelySkewed(double skew, int min, int max){
      return randomSkew(skew) * (max - min) + min;
  }
  
  public static double randomSkew(final double skew){
      final double xVal = Math.random();
      return 2 * normalDist(xVal) * Integral.integrate(-500, skew * xVal, 100000, new Evaluatable() {
  
          @Override
          public double evaluate(double value) {
              return normalDist(value);
          }
      });
  }
  
  public static double normalDist(double x){
      return 1 / Math.sqrt(2 * Math.PI) * Math.pow(Math.E, -x * x / 2);
  }
  
  /** A class to calculate summations and numeric integrals. The
   *  integral is calculated according to the midpoint rule.
   *
   *  Taken from Core Web Programming from 
   *  Prentice Hall and Sun Microsystems Press,
   *  http://www.corewebprogramming.com/.
   *  &amp;copy; 2001 Marty Hall and Larry Brown;
   *  may be freely used or adapted. 
   */
  
  public static class Integral {
    /** Returns the sum of f(x) from x=start to x=stop, where the
     *  function f is defined by the evaluate method of the 
     *  Evaluatable object.
     */
  
    public static double sum(double start, double stop,
                             double stepSize,
                             Evaluatable evalObj) {
      double sum = 0.0, current = start;
      while (current &lt;= stop) {
        sum += evalObj.evaluate(current);
        current += stepSize;
      }
      return(sum);
    }
  
    /** Returns an approximation of the integral of f(x) from 
     *  start to stop, using the midpoint rule. The function f is
     *  defined by the evaluate method of the Evaluatable object.
     */
  
    public static double integrate(double start, double stop,
                                   int numSteps, 
                                   Evaluatable evalObj) {
      double stepSize = (stop - start) / (double)numSteps;
      start = start + stepSize / 2.0;
      return(stepSize * sum(start, stop, stepSize, evalObj));
    }
  }
  
  /** An interface for evaluating functions y = f(x) at a specific
   *  value. Both x and y are double-precision floating-point 
   *  numbers.
   *
   *  Taken from Core Web Programming from 
   *  Prentice Hall and Sun Microsystems Press,
   *  http://www.corewebprogramming.com/.
   *  &amp;copy; 2001 Marty Hall and Larry Brown;
   *  may be freely used or adapted. 
   */
  public static interface Evaluatable {
        public double evaluate(double value);
  }
  </code></pre>
  
  <p>I'm certain it's something very simple</p>
  
  <p>Also, how do I call</p>
  
  <pre><code>getSkewNormal(double skewValue, double x)
  </code></pre>
  
  <p>From a file outside SkewNormal.h?</p>