“呼叫不匹配”使用 boost::bind 时出错
我对 boost::bind 还是个新手,现在移植一个 2 年前(即 2009 年)编写的程序,看到下面的编译错误。任何解决方法的想法将不胜感激。
提取的 cpp 文件:
class ClassA {
private:
cNamespace::Bounds bounds_msg_;
void boundsHandler(const PublisherPtr& p) {
p->publish(bounds_msg_);
}
void funcA() {
node_->advertise<cNamespace::Bounds>("bounds", 10,
boost::bind(&ClassA::boundsHandler, this, _1)); // <---- Line 445
}
};
CMake 时出错:
/home/userA/ClassA.cpp:445: instantiated from here
/usr/include/boost/bind/bind.hpp:313: error: no match for call to ‘(boost::_mfi::mf1<void, ClassA, const PublisherPtr&>) (ClassA*&, const ros::SingleSubscriberPublisher&)’
环境:Ubuntu 10.10,g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
可能不是必需的,但函数 advertise
的 API 参考是 此处,或者:
template<class M >
Publisher advertise (const std::string &topic,
uint32_t queue_size,
const SubscriberStatusCallback &connect_cb,
const SubscriberStatusCallback &disconnect_cb=SubscriberStatusCallback(),
const VoidConstPtr &tracked_object=VoidConstPtr(),
bool latch=false)
I'm still new to boost::bind, and now porting a program that was written 2 yrs ago in 2009, seeing the compile error below. Any idea to workaround would be appreciated.
Extracted cpp file:
class ClassA {
private:
cNamespace::Bounds bounds_msg_;
void boundsHandler(const PublisherPtr& p) {
p->publish(bounds_msg_);
}
void funcA() {
node_->advertise<cNamespace::Bounds>("bounds", 10,
boost::bind(&ClassA::boundsHandler, this, _1)); // <---- Line 445
}
};
Error upon CMake:
/home/userA/ClassA.cpp:445: instantiated from here
/usr/include/boost/bind/bind.hpp:313: error: no match for call to ‘(boost::_mfi::mf1<void, ClassA, const PublisherPtr&>) (ClassA*&, const ros::SingleSubscriberPublisher&)’
Environment: Ubuntu 10.10, g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
Might not be necessary but API reference of function advertise
is here, or:
template<class M >
Publisher advertise (const std::string &topic,
uint32_t queue_size,
const SubscriberStatusCallback &connect_cb,
const SubscriberStatusCallback &disconnect_cb=SubscriberStatusCallback(),
const VoidConstPtr &tracked_object=VoidConstPtr(),
bool latch=false)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来由
boost::bind
生成的函数对象是用与您绑定的函数不同的类型调用的。即它是用 const ros::SingleSubscriberPublisher& 参数调用的,而不是预期的 const PublisherPtr& 。 p。
假设
SubscriberStatusCallback
是一个boost::function
,您应该确保其参数与您绑定的参数匹配。It looks like the function object that is produced by
boost::bind
is called with a different type than the function you bound.i.e. it's called with
const ros::SingleSubscriberPublisher&
argument, instead of the expectedconst PublisherPtr& p
.Assuming
SubscriberStatusCallback
is aboost::function
, you should make sure its argument matches the one you bound.