使用升压::信号时"no matching call"编译器错误

"no matching call" compiler error when using boost::signal

本文关键字:no matching call 错误 编译器 信号      更新时间:2023-10-16

在文件 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
除了

候选人使用"可移植"语法这一事实(不,将我的代码切换为使用可移植样式没有区别)我认为这两个调用之间没有区别,除了我的调用中的最后一件事是int&候选人有int的地方。 我尝试从信号中删除int参数,看看这是否是问题所在,但事实并非如此。

有人知道为什么我会收到此错误吗?

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

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

相关文章: