title: Invalid use of non-static member function c++
body: <p>I am following this <a href="https://sourcemaking.com/design_patterns/state/cpp/1" rel="noreferrer">example</a>. But when I compile, it returns an error:</p>
  
  <blockquote>
    <p>Invalid use of non-static member function</p>
  </blockquote>
  
  <p>at the line</p>
  
  <pre><code>void(Machine:: *ptrs[])() = 
    {
      Machine::off, Machine::on
    };
  </code></pre>
  
  <p>I tried to add <code>static</code> to  <code>void on();</code> at class</p>
  
  <pre><code>class Machine
  {
    class State *current;
    public:
      Machine();
      void setCurrent(State *s)
      {
          current = s;
      }
      static void on(); // I add static here ...
      static void off(); // and here
  };
  </code></pre>
  
  <p>But it complains that </p>
  
  <blockquote>
    <p>Invalid use of member Machine::current in static member function</p>
  </blockquote>
  
  <p>Can you help me fix this?</p>