title: passing function as constructor parameter to base class constructor while initializing
body: <pre><code>#include &lt;iostream&gt;
  #include&lt;cstdio&gt;
  #include&lt;typeinfo&gt;
  
  using std::cout;
  using std::endl;
  
  class foo;
  class bar
  {
      public:
          bar()
          {
          }
          bar(void (*getNextValue)(void)):memberFunctionPointer(getNextValue)
          {
          }
          void calltoderivedslass()
          {
              //  *memberFunctionPointer();
              ((bar*)this)-&gt;bar::memberFunctionPointer;
          }
          void (foo::*memberFunctionPointer)();
  };
  
  class foo : public bar
  {
      public:
          foo( ):bar(static_cast&lt;foo::*memberFunctionPointer&gt;(&amp;foo::hello))
          {
          }
          void hello()
          {
              printf("Hello \n\n");
          }
  };
  void byebye()
  {
      cout &lt;&lt; "bye" &lt;&lt; endl;
  }
  int main()
  {
      foo testfoo;
      //((testfoo).*(testfoo.memberFunctionPointer))();
      return 0;
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>classname.cpp: In constructor "bar::bar(void (*)())":
  classname.cpp:15:68: error: cannot convert "void (*)()" to "void (foo::*)()" in initialization
  classname.cpp: In constructor "foo::foo()":
  classname.cpp:29:25: error: expected type-specifier
  classname.cpp:29:25: error: expected "&gt;"
  classname.cpp:29:25: error: expected "("
  classname.cpp:29:30: error: expected unqualified-id before "*" token
  classname.cpp:31:2: error: expected "{" at end of input
  </code></pre>
  
  <p><strong>Expectations:</strong></p>
  
  <p>I want to initialize the base class  function pointer to initialize it points to derived class member function. I want to initialize that while creating object of derived class. From base class i want to call derived class function using the acquired function pointer.</p>
  
  <p>Thanks in advance for all.</p>