title: boost::function variable is empty in destructor
body: <p>I need to use different implementations of some of the methods in my class, therefore I use a couple of <code>boost::function</code> variables to point to correct method.
  everything seems working except this variable:</p>
  
  <p><code>boost::function&lt;void(void)&gt; onExit</code></p>
  
  <p>which is called in the destructor. Have a look at my simple methods please:</p>
  
  <pre><code>//constructor
  Logger::Logger(std::string id_){
  
      /*...other stuff...*/
      //decision point to use which implementation
      initDef();
  }
  
  //Default Implementation initializer
  void Logger::initDef()
  {
      /*...other stuff...*/
      onExit = boost::bind(&amp;Logger::onExitDef,this);
      if(onExit.empty()){
          std::cout &lt;&lt; "onExit is Empty in initialization" &lt;&lt; std::endl;
      }
  }
  //destructor
  Logger::~Logger(){
      if(onExit.empty()){
          std::cout &lt;&lt; "onExit is Empty in destructor" &lt;&lt; std::endl;
      }
      onExit();//error in here
  }
  </code></pre>
  
  <p>a breakpoint inside <code>initDef()</code> shows the following after initializing <code>onExit</code>. As you can see the <code>vtable</code> is not empty :</p>
  
  <pre><code>    Details:{&lt;boost::function0&lt;void&gt;&gt; = {&lt;boost::function_base&gt; = {vtable = 0x1469681 &lt;void boost::function0&lt;void&gt;::assign_to&lt;boost::_bi::bind_t&lt;void, boost::_mfi::mf0&lt;void, Logger&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;Logger*&gt; &gt; &gt; &gt;(boost::_bi::bind_t&lt;void, boost::_mfi::mf0&lt;void, Logger&gt;,
   boost::_bi::list1&lt;boost::_bi::value&lt;Logger*&gt; &gt; &gt;)::stored_vtable+1&gt;, functor = {obj_ptr = 0xd32806 &lt;Logger::onExitDef()&gt;, type = {type = 0xd32806 &lt;Logger::onExitDef()&gt;, const_qualified = false, volatile_qualified = false}, func_ptr = 0xd32806 &lt;Logger::onExitDef()&gt;, bound_memfunc_ptr = {memfunc_ptr = (void (boost::detail::function::X::*)(boost::detail::function::X * const, int)) 0xd32806 &lt;Logger::onExitDef()&gt;, obj_ptr = 0x45903200}, 
  obj_ref = {obj_ptr = 0xd32806 &lt;Logger::onExitDef()&gt;, is_const_qualified = false, is_volatile_qualified = false}, data = 6 '\006'}}, static args = &lt;optimized out&gt;, static arity = &lt;optimized out&gt;}, &lt;No data fields&gt;}
  </code></pre>
  
  <p>but in the destructor, <code>onExit.empty()</code> holds true(<code>vtable</code> is empty/null) :</p>
  
  <pre><code>    Details:{&lt;boost::function0&lt;void&gt;&gt; = {&lt;boost::function_base&gt; = {vtable = 0x0, functor = {obj_ptr = 0x0, type = {type = 0x0, const_qualified = false, volatile_qualified = false},
   func_ptr = 0x0, bound_memfunc_ptr = {memfunc_ptr = NULL, obj_ptr = 0x0}, obj_ref = {obj_ptr = 0x0, is_const_qualified = false, is_volatile_qualified = false}, data = 0 '\0'}}, static args = &lt;optimized out&gt;, static arity = &lt;optimized out&gt;}, &lt;No data fields&gt;}
  </code></pre>
  
  <p>and naturally, the obvious error is:</p>
  
  <pre><code>terminate called after throwing an instance of 'boost::exception_detail::clone_impl&lt;boost::exception_detail::error_info_injector&lt;boost::bad_function_call&gt; &gt;'
    what():  call to empty boost::function
  </code></pre>
  
  <p>I will appreciate you you share your thoughts with me: how does this happen and how do you think I can solve this issue?</p>
  
  <p>thanks</p>