Ошибка компиляции "нет соответствующего вызова" при использовании boost :: signal - PullRequest
0 голосов
/ 12 мая 2011

В файле 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без разницы) Я не вижу разницы между двумя вызовами, за исключением того, что последнее, что есть в моем вызове, это int&, где у кандидата есть int.Я попытался удалить параметр int из сигнала, чтобы увидеть, была ли это проблема, а это не так.

Кто-нибудь видел, почему я получаю эту ошибку?

1 Ответ

1 голос
/ 12 мая 2011

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

Почему параметры здесь постоянные? В объявлении сигнала они не являются постоянными.

...