c++ - 使用 boost::signal 时出现 "no matching call"编译器错误

标签 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

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

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

最佳答案

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

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

关于c++ - 使用 boost::signal 时出现 "no matching call"编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5971266/

相关文章:

c++ - 在 TinyXML 中解析 <multi_path literal ="not_measured"/>

c++ - 调试器问题

c++ - 为什么我得到 "error C2006: ' #include' : expected a filename, found 'identifier' "?

c++ - 传递包装器使用的非托管成员函数指针,以将其连接到 c++/cli 中的信号

c++ - 公共(public) boost::signal 对象

c++ - 使用库编译 C++ 项目

c++ - 如何在 OpenGL 中正确旋转和缩放对象?

c++ - boost::signal slot_type 模板

c++ - 如何从循环中的 vector 调用 shared_ptr<boost::signal>?

c++ - 我可以使用 Boost Signals2 和 Threads 在 C++ 中创建软件看门狗计时器线程吗?