gpt4 book ai didi

c++ - 关于 Boost Signals2,没有名为 'apply' 的类模板

转载 作者:行者123 更新时间:2023-11-28 05:47:57 24 4
gpt4 key购买 nike

我已经遵循了 Boost 教程“Passing Slots (Intermediate)”,引用文献 [1] 中的这封信,但我的代码出现了一个奇怪的错误,我无法破译或找不到任何帮助。我的代码如下:

[ 1 ] - http://www.boost.org/doc/libs/1_55_0/doc/html/signals2/tutorial.html#idp204830936

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;

如果有人能对此提供帮助,我们将不胜感激。正如我之前所说,我做了一些研究,但并没有真正找到任何东西。这对我来说似乎有点独特,也许,我确实严格按照教程进行操作。我知道这并不总是正确的做法,但根据我通过研究收集到的信息,这段代码应该可以工作。

最佳答案

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

关于c++ - 关于 Boost Signals2,没有名为 'apply' 的类模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35847867/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com