title: Calling Member Function Pointers
body: <p>I am having trouble calling a function pointer inside a structure.  I have used this approach before outside of classes, but now that I am trying it inside a class method using function pointers to other class methods.... I am receiving a compiler error. Here is my class:</p>
  
  <pre><code>class Myclass
  {
      int i;
  
      void cmd1(int)
      {}
  
      void cmd2(int)
      {}
  
      void trans()
      {
          const struct
          {
              std::string cmd;
              void (Myclass::*func)(int)
          }
          CmdTable[] =
          {
              { "command1", &amp;Myclass::cmd1 },
              { "command2", &amp;Myclass::cmd2 }
          };
  
          CmdTable[0].func(i);
          CmdTable[1].func(i);
      }
  };
  </code></pre>
  
  <p>The lines <code>CmdTable[0].func(i);</code> and <code>CmdTable[1].func(i);</code> both provide the following
  error:
  Error: expression must have (pointer-to-) function type.</p>
  
  <p>I realize there are probably better ways of doing this, but I'm rather curious as to why what I've written doesn't work.  Any explanation would be greatly appreciated.</p>