“no match for call” error using boost::bind

笑着哭i 提交于 2019-12-10 17:03:11

问题


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)

回答1:


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 expected const PublisherPtr& p.

Assuming SubscriberStatusCallback is a boost::function, you should make sure its argument matches the one you bound.



来源:https://stackoverflow.com/questions/7642359/no-match-for-call-error-using-boostbind

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!