title: Function as a member "variable" in class
body: <p>I was thinking about how to improve my simple calculator using some advanced techniques. I came to question, is there some way to create a class with function you could define per instance:</p>
  
  <pre><code>class Function
  {
  public:
      Function(function);
      ~Function();
  
  private:
      function;
  };
  </code></pre>
  
  <p>So for example you create an instance</p>
  
  <pre><code>Function divide(int x / int y); //For example
  </code></pre>
  
  <p>I hope you understand the question.</p>
  
  <p>EDIT:</p>
  
  <p>So I studied the <code>void (*foo)(int)</code> method. It could be used. But the initial idea was to create a generic function that holds the function itself in it. Not just a pointer to a function defined outside. So you could do something like this:</p>
  
  <pre><code>int main() {
  
  //Define the functions
  Function divide( X / Y ); //Divide
  Function sum( X + Y ); //Sum
  
  //Ask the user what function to call and ask him to enter variables x and y
  
  //User chooses divide and enters x, y 
  cout &lt;&lt; divide.calculate(x, y) &lt;&lt; endl;
  
  return 0;
  }
  </code></pre>
  
  <p>Answer:
  @Chris Drew pointed out:<br>
  <i>Sure, your <code>Function</code> can store a <code>std::function&lt;int(int, int)&gt;</code> and then you can construct <code>Function</code> with a lambda: e.g: <code>Function divide([](int x,int y){return x / y;});</code> But then I'm not sure what your <code>Function</code> offers that you can't just do with <code>std::function</code>. </i></p>
  
  <p>It answers my question, unfortunately my question was put on hold so I cannot mark the question resolved.</p>