Boost::bind重载操作符导致Boost未定义引用错误
Boost undefined reference error with boost::bind overloaded operators
所讨论的代码:
boost::function<bool()> isSpecialWeapon = boost::bind(&WeaponBase::GetType,this) == WeaponType::SPECIAL_WEAPON;
我得到的错误是这样的:
undefined reference to `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)'
如果您不能让boost::bind
按您的愿望工作,您可以尝试Boost。凤凰或Boost。
尝试使用boost::pheonix::bind
(来自boost . phoenix)代替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();
}
或者,您也可以使用boost::lambda::bind
(来自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();
}
相关文章:
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- Boost Python Numpy - 要初始化的未定义引用
- boost::any 如何检查空值/未定义的值
- 如何修复架构x86_64的未定义符号,Boost Asio 1.58
- 使用 Boost/Python 的未定义符号 - 复杂
- 我仍然收到此错误未定义的引用:boost::log::v2_mt_posix::trivial::logger::get
- C++ Boost:在Windows中对boost::system::generic_category()的未定义引用
- 链接到 Boost 1.63 静态库时未定义的引用
- C++ CMake 构建错误:未定义对"boost::throw_exception(std::exception const&)"的引用
- 针对 QNX 交叉编译后,boost 文件系统 (1.63) 失败并出现未定义的引用错误
- 对"boost::system::system_category()"的未定义引用
- boost::system::generic_category 静态链接后未定义
- BOOST :: ASIO :: CO_SPAWN在MSVC中未定义
- 对 Boost::p rogram_options in Vowpalwabbit 编译的未定义引用,Ubuntu 16
- Boost.Python - ImportError:动态模块未定义模块导出函数(PyInit_example)
- Boost Log-使用全局记录器时未定义的参考
- C++ Boost:未定义的对 boost::system::generic_category() 的引用
- C++ BOOST 未定义对 'boost::filesystem::d etail::copy_file 的引用
- Boost::bind重载操作符导致Boost未定义引用错误
- Opencv + Boost:未定义的引用