title: callback in C++ struct
body: <p>I have been trying to implement a callback function in c++. Within a class, I have a struct, a number of methods, and a method that creates an instance of the struct with one of the other methods as its argument. </p>
  
  <p>The struct has many other variables, but an illustration is depicted here:</p>
  
  <pre><code>class MYCLASS
  {
  public:
      MYCLASS();
  
      struct TEST{
          std::function&lt;int(int)&gt; foo;
      };
  
      int plus(int x){
          return x + 1;
      }
  
      int minus(int x){
          return x - 1;
      }
  
      void sim(){
          TEST T;             // make an instance of TEST
          T.foo = plus(5);    // assign TEST.foo a function (plus or minus)  
          T.foo();            // call the method we assigned
      }
  };
  </code></pre>
  
  <p>Within the <code>sim</code> method, I want to create an instance of <code>test</code> and give it either <code>plus</code> or <code>minus</code>, depending on some criterion. Both lines where I try and give the instance <code>T</code> a <code>plus</code> function and subsequently call it are incorrect. </p>