title: Member function pointer in C++ for_each
body: <p>I'm developing a small Virtual Machine in C++ for a school project, which should work like dc command, and is composed of a Input Output element, a Chipset, a Cpu and Ram. I'm currently working on the chipset, in which I've implemented a little parsing class in order to be able to get some Asm instructions from standard input or file, and then push this instructions to the Cpu. </p>
  
  <p>The problem is: my instructions are sorted in a std::list, and I'd like to be able to push them each by each with a foreach instruction. To do that I need to be able to call my member function "push_instruction" as the function pointer F of for_each; and I wasn't able to find the trick to do that... </p>
  
  <p>Any ideas?
  here's my code:</p>
  
  <pre><code>/*
  ** Function which will supervise
  ** the lexing and parsing of the input (whether it's std_input or a file descriptor)
  ** the memory pushing of operands and operators
  ** and will command the execution of instructions to the Cpu
  */
  void                    Chipset::startExecution()
  {
      /*
      ** My parsing 
      ** Instructions
      **
      */
  
      for_each(this-&gt;_instructList.begin(), this-&gt;_instructList.end(), this-&gt;pushInstruction);
  }
  
  
  void                    Chipset::pushInstruction(instructionList* instruction)
  {
      if (instruction-&gt;opCode == PUSH)
        this-&gt;_processor-&gt;pushOperand(instruction-&gt;value, Memory::OPERAND, Memory::BACK);
      else if (instruction-&gt;opCode == ASSERT)
        this-&gt;_processor-&gt;pushOperand(instruction-&gt;value, Memory::ASSERT, Memory::BACK);
      else
        this-&gt;_processor-&gt;pushOperation(instruction-&gt;opCode);
  }
  </code></pre>