2011-10-04 85 views
4

「沒有匹配的調用」錯誤我仍然對boost :: bind新手,現在正在移植一個在2009年2年前編寫的程序,看到下面的編譯錯誤。任何想法解決方法將不勝感激。使用boost :: bind

提取CPP的文件:在CMake的

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 
    } 
}; 

錯誤:

/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,克++(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) 

回答

4

它看起來像boost::bind生成的函數對象被調用的類型與您綁定的函數不同。

即它被稱爲const ros::SingleSubscriberPublisher&參數,而不是預期的const PublisherPtr& p

假設SubscriberStatusCallbackboost::function,您應該確保它的參數與您綁定的參數匹配。