title: Call a pointer-to-function outside the structure
body: <p>I have a structure, inside it a pointer to function from the same structure. And now I need to call a pointer to function outside the structure. I give an example of the code below:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct test {
      void (test::*tp)(); // I need to call this pointer-to-function
      void t() {
          std::cout &lt;&lt; "test\n";
      }
      void init() {
          tp = &amp;test::t;
      }
      void print() {
          (this-&gt;*tp)();
      }
  };
  void (test::*tp)();
  
  int main() {
      test t;
      t.init();
      t.print();
      (t.*tp)(); // segfault, I need to call it
      return 0;
  }
  </code></pre>