title: Dynamically change the behavior of member functions in C++
body: <p>For a homework, we need to modify a variety of images with multiple different algorithms and format a document with our answers. I have already coded the algorithms in C++, but I want to write a program that will modify the images and format the document automatically. To do this, I want to have a class of the form</p>
  
  <pre><code>class A
  {
      void f1(Image img)
      {
      // do something to the image
      }
      void f2(Image img)
      {
      // do something else to the image
      }
      public:
         void setFunction(bool choice)
         {
            if(choice)
            {
            // define this.operator() = f1
            }
            else
            {
            // define this.operator() = f2
            }
         }
  }
  </code></pre>
  
  <p>The reason I want to do this is because the homework requires us to compute different properties for the images, but most of the properties are repeated accross questions. Therefore, I want to write a single function of the form</p>
  
  <pre><code>void answerQuestion(Image img, A imgProcessor)
  {
      // load img, call imgProcessor(img)
      // and get the necessary properties from
      // img to answer the questions
  }
  </code></pre>
  
  <p>This way, I can just do something like <code>imgProcessor.setFunction(choice)</code> before passing the <code>imgProcessor</code> object to <code>answerQuestion</code>. I want to use an object because questions are split into several parts, so I would like the <code>imgProcessor</code> object to hold on to some information required for the rest of the problem. 
  I don't know how to dynamically define or redefine the <code>operator()</code> method, or if it is even possible. Of course, I am indifferent between overloading the call operator or just declaring my own method, but I want to be able to use this call in the same way accross the code. Is this possible in C++?</p>