title: Member function pointer of forward declared class
body: <p>The header <code>common.h</code> forward declares a class <code>Test</code> and a function receiving a member function pointer:</p>
  
  <pre><code>class Test;
  
  void func(const Test &amp;t, int (Test::*f)() const, int x, int y);
  </code></pre>
  
  <p>In the source file <code>target.cpp</code>, I define the function such that</p>
  
  <pre><code>#include "common.h"
  
  void func(const Test &amp;t, int (Test::*f)() const, int x, int y) {
      std::cout &lt;&lt; "f: " &lt;&lt; (t.*f)() &lt;&lt; ", x: " &lt;&lt; x &lt;&lt; ", y: " &lt;&lt; y &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>In my main file, I define the class <code>Test</code> and use the function <code>func</code>:</p>
  
  <pre><code>class Test {
  public:
      int example() const { return 1; }
  };
  
  #include "common.h"
  
  int main() {
      Test t;
      func(t, &amp;Test::example, 0xaaaaaaaa, 0xbbbbbbbb);
      return 0;
  }
  </code></pre>
  
  <p>Obviously this is a bit smelly since pointers to member functions are sometimes more than a simple pointer. But the resulting behavior is a bit overwhelming: The given parameters <code>0xaaaaaaaa</code> and <code>0xbbbbbbbb</code> won't be passed correctly to the function. Or to be more precise, the function <code>func</code> interprets the given stack differently than the data is pushed on the stack by the caller. The size of <code>f</code> depends on whether the class is only forward declared or actually defined. The output compiled with Visual Studio 2013 is:</p>
  
  <pre><code>f: 1, x: 0, y: 2130567168
  </code></pre>
  
  <p>I thought, <em>if</em> a forward declaration is sufficient, it <em>really</em> doesn't matter whether there's a definition given or not.</p>