title: C++ Function Pointer assignment cannot convert types inside a class
body: <p>I have a simple class that has a pointer to a function. The constructor points it to the function "morning()" and I get the error message when compiling:</p>
  
  <pre><code>error: cannot convert ‘Test::morning’ from type ‘void (Test::)()’ to type ‘Test::function {aka void (*)()}’
       Test() {assignPtr = morning;}
  </code></pre>
  
  <p>The code does compile when the "morning()" and the typedef are declared outside the function and I can't figure out how to make it work within the current class.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  class Test {
    public:
      Test() {assignPtr = morning;}
      void say(std::string a) {name = a; assignPtr();};
    private:
      typedef void(*function)();
      void morning() {std::cout &lt;&lt; "Good morning, " &lt;&lt; name &lt;&lt; std::endl;}
      void night() {};
      function assignPtr;
      std::string name;
  };
  
  int main() {
      Test a;
      a.say("Miguel");
  }
  </code></pre>