没有关于Boost Signals2的名为'apply'的类模板

时间:2016-03-07 15:42:10

标签: c++ c++11 boost signals

我已经按照Boost教程“传递插槽(中级)”,在参考文献[1]中写了这封信但是我的代码出现了一个奇怪的错误,我无法破译或找到任何帮助。我的代码如下:

[1] - Bar chart

namespace GekkoFyre {
class TuiHangouts {
private:
    typedef boost::signals2::signal<void()> onRosterUpdate;
    typedef onRosterUpdate::slot_type onRosterUpdateSlotType;

    void logMsgs(std::string message, const xmppMsgType &msgType);
    void logMsgsDrawHistory();

    // Slots
    boost::signals2::connection doOnRosterUpdate(const onRosterUpdateSlotType &slot);
    onRosterUpdate rosterUpdate;
};
}

boost::signals2::connection GekkoFyre::TuiHangouts::doOnRosterUpdate(
        const GekkoFyre::TuiHangouts::onRosterUpdateSlotType &slot)
{
    return rosterUpdate.connect(slot);
}

问题在于具体:

void GekkoFyre::TuiHangouts::logMsgs(std::string message, const xmppMsgType &msgType)
{
    doOnRosterUpdate(&GekkoFyre::TuiHangouts::logMsgsDrawHistory);
}

我收到错误:

In file included from /usr/include/boost/function/detail/maybe_include.hpp:13:0,
                 from /usr/include/boost/function/detail/function_iterate.hpp:14,
                 from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:47,
                 from /usr/include/boost/function.hpp:64,
                 from /usr/include/boost/signals2/signal.hpp:18,
                 from /usr/include/boost/signals2.hpp:19,
                 from /home/phobos/Programming/gecho/src/tui/chat.hpp:47,
                 from /home/phobos/Programming/gecho/src/tui/chat.cpp:35:
/usr/include/boost/function/function_template.hpp: In instantiation of 'void boost::function0<R>::assign_to(Functor) [with Functor = void (GekkoFyre::TuiHangouts::*)(); R = void]':
/usr/include/boost/function/function_template.hpp:722:7:   required from 'boost::function0<R>::function0(Functor, typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral<Functor>::value)>::value), int>::type) [with Functor = void (GekkoFyre::TuiHangouts::*)(); R = void; typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral<Functor>::value)>::value), int>::type = int]'
/usr/include/boost/function/function_template.hpp:1071:16:   required from 'boost::function<R()>::function(Functor, typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral<Functor>::value)>::value), int>::type) [with Functor = void (GekkoFyre::TuiHangouts::*)(); R = void; typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral<Functor>::value)>::value), int>::type = int]'
/usr/include/boost/function/function_template.hpp:1126:5:   required from 'typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral<Functor>::value)>::value), boost::function<R()>&>::type boost::function<R()>::operator=(Functor) [with Functor = void (GekkoFyre::TuiHangouts::*)(); R = void; typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral<Functor>::value)>::value), boost::function<R()>&>::type = boost::function<void()>&]'
/usr/include/boost/signals2/detail/slot_template.hpp:160:24:   required from 'void boost::signals2::slot<R(Args ...), SlotFunction>::init_slot_function(const F&) [with F = void (GekkoFyre::TuiHangouts::*)(); SlotFunction = boost::function<void()>; R = void; Args = {}]'
/usr/include/boost/signals2/detail/slot_template.hpp:85:27:   required from 'boost::signals2::slot<R(Args ...), SlotFunction>::slot(const F&) [with F = void (GekkoFyre::TuiHangouts::*)(); SlotFunction = boost::function<void()>; R = void; Args = {}]'
/home/phobos/Programming/gecho/src/tui/chat.cpp:802:74:   required from here
/usr/include/boost/function/function_template.hpp:924:9: error: no class template named 'apply' in 'struct boost::detail::function::get_invoker0<boost::detail::function::member_ptr_tag>'
         handler_type;

如果有人可以提供帮助,那么我们将非常感激。正如我之前所说,我做了一些研究,并没有真正找到任何东西。这对我来说似乎有点独特,我确实按照教程来写信。我知道这并不总是正确的事情,但从我通过研究收集的内容来看,这段代码应该可行。

1 个答案:

答案 0 :(得分:1)

&GekkoFyre::TuiHangouts::logMsgsDrawHistory是一个成员函数指针,其类型为void (GekkoFyre::TuiHangouts::*)()。这不像任何其他函数,因此不能像任何其他函数一样调用它。 Signals2将尝试使用语法func()调用此方法,但此处没有this指针。要为其提供this指针,您将使用语法(p->*func)()。这里的p成为this指针。 boost::bind(自2011年以来的C ++标准中称为std::bind)将其作为一个函数对象包装起来,通过调用{{1}将 调用为func() }}