Boost logo

Boost Users :

From: Daniel Lidström (daniel.lidstrom_at_[hidden])
Date: 2008-02-22 05:04:36


Hello!

I'm trying to use boost::bind and boost::function to perform a callback
mechanism.
However, the VC2005 compiler crashes for some reason. Let me show the code
right away:

#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/any.hpp>
#include <boost/noncopyable.hpp>
#include <iostream>
#include <tchar.h>

struct Fl_Widget;

typedef boost::function<void (Fl_Widget&, const boost::any&)> CBF_Callback;

struct Fl_Widget
{
   CBF_Callback cbf_callback_;
   boost::any user_data_;

   //Three calls to set or probe that functor callback variable.
   CBF_Callback cbf_callback() const {return cbf_callback_;}
   void cbf_callback(CBF_Callback c, const boost::any& p) {cbf_callback_=c;
user_data_=p;}
   void cbf_callback(CBF_Callback c) {cbf_callback_=c;}

   //Calls to do the functor callback
   void do_cbf_callback() {cbf_callback_(boost::ref(*this),user_data_);}
   // override user_data_
   void do_cbf_callback(const boost::any& user_data)
{cbf_callback_(boost::ref(*this),user_data);}
};

struct GUI : private boost::noncopyable
{
   static GUI& Instance()
   {
      static GUI theGUI;
      return theGUI;
   }
   void print()
   {
      std::cout << "Inside GUI" << std::endl;
   }
private:
   GUI(){}
};

struct RailCaterpillarControllerGUI
{
   Fl_Widget widget;

   RailCaterpillarControllerGUI()
   {
      // cbToggleDeadZone should be called by widget's callback
      CBF_Callback
callback(boost::bind(&RailCaterpillarControllerGUI::cbToggleDeadZone,
this));
      widget.cbf_callback(callback);
   }

   void cbToggleDeadZone(Fl_Widget& widget, const boost::any& data)
   {
      // assume data is reference to the GUI instance
      boost::any_cast<boost::reference_wrapper<GUI> >(data).get().print();
   }
};

int _tmain(int argc, TCHAR** argv)
{
   RailCaterpillarControllerGUI controller;
   controller.widget.do_cbf_callback(boost::ref(GUI::Instance()));
}

Compiling gives this:
1>------ Build started: Project: test, Configuration: Debug Win32 ------
1>Compiling...
1>test.cpp
1>c:\users\daniel.sbg\programming\boost_1_34_1\boost\bind.hpp(1575) :
warning C4180: qualifier applied to function type has no meaning; ignored
1> c:\users\daniel.sbg\programming\boost_1_34_1\boost\bind.hpp(1609)
: see reference to class template instantiation 'boost::_bi::add_cref<Pm,I>'
being compiled
1> with
1> [
1> Pm=void (__thiscall RailCaterpillarControllerGUI::*
)(Fl_Widget &,const boost::any &),
1> I=1
1> ]
1> c:\users\daniel.sbg\programming\test\test.cpp(48) : see reference
to class template instantiation 'boost::_bi::dm_result<Pm,A1>' being
compiled
1> with
1> [
1> Pm=void (__thiscall RailCaterpillarControllerGUI::*
)(Fl_Widget &,const boost::any &),
1> A1=RailCaterpillarControllerGUI *
1> ]
1>c:\users\daniel.sbg\programming\boost_1_34_1\boost\mem_fn.hpp(318) :
warning C4180: qualifier applied to function type has no meaning; ignored
1>
c:\users\daniel.sbg\programming\boost_1_34_1\boost\bind\bind_template.hpp(22
5) : see reference to class template instantiation 'boost::_mfi::dm<R,T>'
being compiled
1> with
1> [
1> R=void (Fl_Widget &,const boost::any &),
1> T=RailCaterpillarControllerGUI
1> ]
1>Project : error PRJ0002 : Error result 255 returned from 'C:\Program
Files\Microsoft Visual Studio 8\VC\bin\cl.exe'.

The compiler seems to crash when trying to compile the
RailCaterpillarControllerGUI constructor.
Any ideas why?
I'm using 8.0.50727.867 (vsvista.050727-8600), boost-1.34.1

Thanks in advance!

-- 
Daniel

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net