c++ - Boost undefined reference error with boost::bind overloaded operators -


the code in question:

boost::function<bool()> isspecialweapon = boost::bind(&weaponbase::gettype,this) == weapontype::special_weapon; 

the error so:

 undefined reference `boost::_bi::bind_t<bool, boost::_bi::equal,   boost::_bi::list2<boost::_bi::bind_t<weapontype::guns,   boost::_mfi::cmf0<weapontype::guns, weaponbase>,    boost::_bi::list1<boost::_bi::value<weaponbase*> > >,   boost::_bi::add_value<weapontype::guns>::type> > boost::_bi::operator==  <weapontype::guns, boost::_mfi::cmf0<weapontype::guns, weaponbase>,   boost::_bi::list1<boost::_bi::value<weaponbase*> >, weapontype::guns>  (boost::_bi::bind_t<weapontype::guns, boost::_mfi::cmf0<weapontype::guns, weaponbase>,   boost::_bi::list1<boost::_bi::value<weaponbase*> > > const&, weapontype::guns)' 

if can't boost::bind work desire, can try boost.pheonix or boost.lamda workaround.

try using boost::pheonix::bind (from boost.pheonix) instead of boost::bind:

#include <boost/phoenix/operator.hpp> #include <boost/phoenix/bind/bind_member_function.hpp> #include <boost/function.hpp> #include <iostream>  enum weapontype {melee, ranged, special};  class sword { public:     weapontype gettype() const {return melee;}      void test()     {         namespace bp = boost::phoenix;         boost::function<bool()> isspecialweapon =             bp::bind(&sword::gettype, this) == special;         std::cout << "isspecialweapon() = " << isspecialweapon() << "\n";     }  };  int main() {     sword sword;     sword.test(); } 

alternatively, use boost::lambda::bind (from boost.lambda):

#include <boost/function.hpp> #include <boost/lambda/bind.hpp> #include <boost/lambda/lambda.hpp> #include <iostream>  enum weapontype {melee, ranged, special};  class sword { public:     weapontype gettype() const {return melee;}      void test()     {         boost::function<bool()> isspecialweapon =             boost::lambda::bind(&sword::gettype, this) == special;         std::cout << "isspecialweapon() = " << isspecialweapon() << "\n";     }  };  int main() {     sword sword;     sword.test(); } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -