使用boost :: signal时“无匹配调用”编译器错误

时间:2011-05-11 22:18:00

标签: c++ boost-signals

在文件A.hpp中,我有

extern boost::signal<void (model::Bullet&, Point&, Point&, int)> signal_createBullet;

所以在文件A.cpp中,我有

boost::signal<void (model::Bullet&, Point&, Point&, int)> signal_createBullet;

在文件B.hpp中,我有一个类Entities,它有一个静态成员函数receiveSignalCreateBullet我希望与signal_createBullet连接,如下所示:(为简洁省略了名称空间)

class Entities
{
    Entities()
    {
        signal_createBullet.connect(&receiveSignalCreateBullet);
    }

    public:
        static void receiveSignalCreateBullet(const Bullet&, const Point&, const Point&, const int);
};

inline static void receiveSignalCreateBullet(...) { ... }

最后在文件C.cpp中,我使用signal_createBullet这样:

signal_createBullet(bullet, pos, bulletVector, count);

A和B编译成功(使用g ++),但C失败并显示以下错误消息:

In member function ‘virtual void thrl::model::SingleStream::shoot(const thrl::utl::Point&, const   thrl::utl::Point&, const thrl::utl::Point&) const’:
src/Shot.cpp:25: error: no match for call to ‘(boost::signal4<void, thrl::model::Bullet&,  thrl::utl::Point&, thrl::utl::Point&, int, boost::last_value<void>, int, std::less<int>,   boost::function4<void, thrl::model::Bullet&, thrl::utl::Point&, thrl::utl::Point&, int> >) (const   thrl::model::Bullet&, const thrl::utl::Point&, thrl::utl::Point&, int&)’
/usr/local/include/boost/signals/signal_template.hpp:330: note: candidates are: typename   boost::signal4<R, T1, T2, T3, T4, Combiner, Group, GroupCompare, SlotFunction>::result_type   boost::signal4<R, T1, T2, T3, T4, Combiner, Group, GroupCompare, SlotFunction>::operator()(T1, T2, T3, T4)   [with R = void, T1 = thrl::model::Bullet&, T2 = thrl::utl::Point&, T3 = thrl::utl::Point&, T4 = int,   Combiner = boost::last_value<void>, Group = int, GroupCompare = std::less<int>, SlotFunction =   boost::function4<void, thrl::model::Bullet&, thrl::utl::Point&, thrl::utl::Point&, int>]
/usr/local/include/boost/signals/signal_template.hpp:370: note:                 typename   boost::signal4<R, T1, T2, T3, T4, Combiner, Group, GroupCompare, SlotFunction>::result_type   boost::signal4<R, T1, T2, T3, T4, Combiner, Group, GroupCompare, SlotFunction>::operator()(T1, T2, T3, T4)   const [with R = void, T1 = thrl::model::Bullet&, T2 = thrl::utl::Point&, T3 = thrl::utl::Point&, T4   = int, Combiner = boost::last_value<void>, Group = int, GroupCompare = std::less<int>, SlotFunction =   boost::function4<void, thrl::model::Bullet&, thrl::utl::Point&, thrl::utl::Point&, int>]

在尝试解决这个问题时,我将我的调用格式化,并在错误消息中第一个候选人更容易比较它们:

// my call
‘(
    boost::signal
    <
        void
        (
            thrl::model::Bullet&, 
            thrl::utl::Point&, 
            thrl::utl::Point&, 
            int
        ), 
        boost::last_value<void>, 
        int, 
        std::less<int>, 
        boost::function
        <
            void
            (
                thrl::model::Bullet&, 
                thrl::utl::Point&, 
                thrl::utl::Point&, 
                int
            )
        > 
    >
) 
(
    const thrl::model::Bullet&, 
    const thrl::utl::Point&, 
    thrl::utl::Point&, 
    int&
)’

// what g++ expects
typename boost::signal4<R, T1, T2, T3, T4, Combiner, Group, GroupCompare, SlotFunction>::result_type 
    boost::signal4<R, T1, T2, T3, T4, Combiner, Group, GroupCompare, SlotFunction>::operator()(T1, T2, T3, T4) 
    [ with
        R  = void, 
        T1 = thrl::model::Bullet&, 
        T2 = thrl::utl::Point&, 
        T3 = thrl::utl::Point&, 
        T4 = int, 
        Combiner = boost::last_value<void>, 
        Group = int, 
        GroupCompare = std::less<int>, 
        SlotFunction = boost::function
        <
            void
            (
                thrl::model::Bullet&, 
                thrl::utl::Point&, 
                thrl::utl::Point&, 
                int
            )
        >
    ]
// the second candidate is the same as the first, except that it's const

除了候选人使用'Portable'语法之外,(并且不,切换我的代码使用Portable风格没有区别)我看到两个调用之间没有区别,除了我调用的最后一件事是{ {1}}候选人的int&。我尝试从信号中删除int参数以查看是否存在问题,但事实并非如此。

任何人都明白为什么我会收到此错误?

1 个答案:

答案 0 :(得分:1)

  

static void receiveSignalCreateBullet(const Bullet&amp;,const Point&amp;,const Point&amp;,const int);

为什么这里的参数是const?在信号声明中,它们不是常量。