c++ - 使用 boost::bind 时出现 "no match for call"错误

标签 c++ 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 引用是 here ,或者:

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)

最佳答案

看起来 boost::bind 生成的函数对象被调用的类型与您绑定(bind)的函数不同。

即它使用 const ros::SingleSubscriberPublisher& 参数调用,而不是预期的 const PublisherPtr& p

假设 SubscriberStatusCallback 是一个 boost::function,您应该确保它的参数与您绑定(bind)的参数匹配。

关于c++ - 使用 boost::bind 时出现 "no match for call"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7642359/

相关文章:

c++ - 在 cpp 文件中正确使用函数定义的命名空间

c++ - 使用 STL/Boost/Lambdas 调整映射迭代器

c++ - 读取字符串 C++ 的字符时出错

c++ - 为什么可以在 .h 接口(interface)和 .cpp 实现中拆分非模板类?

c++ - 期望一个类或命名空间;语法正确

c++ - 数组结构与结构数组

c++ - 使用 boost::bind 但允许传递任何附加参数

c++ - 我可以将绑定(bind)函数存储在容器中吗?

c++ - 键入将在 boost::bind 中使用的函数指针

c++ - boost::bind() 一个以对象指针作为占位符的 boost::function 的成员函数?