title: Member attributes that are functions in C++
body: <p>I'm trying to teach myself some C++ and as an initial project, I want to create code for performing Newton's method on functions of a single variable. I want to make a class <code>ObjectiveFunction</code> that stores user-defined functions for the objective function, the first derivative, and the second derivative.</p>
  
  <p>I want the constructor of <code>ObjectiveFunction</code> to take between 0 and 3 arguments, where the arguments themselves are functions:</p>
  
  <pre><code>// ObjectiveFunction.h
  // Class definition for an Objective Function object.
  
  #ifndef OBJECTIVE_H
  #define OBJECTIVE_H
  
  class ObjectiveFunction
  {
      public:
          // Constructors
  
          // Default constructor
          ObjectiveFunction();
  
          // Constructor with just objective function.
         ObjectiveFunction(double f(double));
  
         // Constructor with objective function and derivative function.
         ObjectiveFunction(double f(double), double fp(double));
  
         // Constructor with objective, derivative, and second derivative functions.
         ObjectiveFunction(double f(double), double fp(double), double fpp(double));
  
         // Methods
         void setObjectiveFunction(double f(dobule));
         void setDerivativeFunction(double f(double));
         void setSecondDerivativeFunction(double f(double));
  
         double evalObjectiveFunction(double);
         double evalDerivativeFunction(double);
         double evalSecondDerivativeFunction(double);
  
      private:
         // Storage for the functions.
         // This is the part I'm not sure of.
  
         // Attempt with function pointers
         double (*objFunc)(double);
         double (*d1Func)(double);
         double (*d2Func)(double);
  
  };
  
  #endif // OBJECTIVE_H
  </code></pre>
  
  <p>How would I create private data members that themselves are functions. I want to create functions objects that (except for being private) would be accessible like <code>foo.obj_func(3.0)</code> or <code>foo.deriv_func(3.0)</code>, where <code>obj_func</code> gets set by the constructor based on the functions that the user passes to the class.</p>
  
  <p>What is the right way to do this? It would be best if there is a way that does not rely on using a pointer to a function object, but I guess if that's the only way then it's what I'll have to learn.</p>