【问题标题】:"no matching call" compiler error when using boost::signal使用 boost::signal 时出现“没有匹配的调用”编译器错误
【发布时间】:2011-05-11 22:18:00
【问题描述】:

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

除了候选人使用“便携式”语法这一事实之外,(不,将我的代码切换为使用便携式风格没有任何区别)我认为这两个调用之间没有区别,除了我调用中的最后一件事是 @ 987654331@,其中候选人有int。我尝试从信号中删除 int 参数以查看是否是问题所在,但不是。

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

【问题讨论】:

    标签: c++ boost-signals


    【解决方案1】:

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

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

    【讨论】:

    • 啊!它们最初是 const,而当我试图让代码正常工作时,我将它们设为非 const,并忘记将它们改回来。感谢您为我监视显而易见的事情。 :)
    猜你喜欢
    • 1970-01-01
    • 2013-08-18
    • 2013-11-21
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 2020-10-02
    • 2021-12-27
    相关资源
    最近更新 更多