错误错误:没有名为“type”的类型调用 ioService()->post(std::bind(some argmumet) 时

发布于 2025-01-14 14:34:38 字数 2000 浏览 2 评论 0 原文

class LogSyslogTest{
 using LogSyslogCbFn = std::function<status(Ipc::Instream& stream)>;
static void v4Handler(const LogSyslogHdr& logSyslogHdr, const Ipc::Ipv4& ipv4,
                        const Layer4Bytes& l4Bytes, CbFn fn) {
        Ipc::Outstream out;
        out << logSyslogHdr;
        out << ipv4;
        out << l4Bytes.sPort;
        out << l4Bytes.dPort;
        Ipc::Instream in{out.data(), out.size()};
        fn(in);
}
}
//calling using gtest
Test F(LogSyslogTest, Ipv4Test) {
    LogSyslogHdr logSyslogHdr;
    getLogSyslogHdrIpv4(logSyslogHdr); //fills data

    Ipc::Ipv4 ipv4;
    getIpv4Hdr(ipv4);  //fills data

    Layer4Bytes l4Bytes;
    getL4Bytes1(l4Bytes);  //fills data

    for (int itr = 0; itr < 10000; ++itr) {
        ioService()->post(std::bind(LogSyslogTest::v4Handler, logSyslogHdr,
                                    ipv4, l4Bytes,Handler::processLog));
}

这是抽象代码片段。编译此文件时,我收到以下错误。 错误1-->

/volume/evo/files/opt/poky/3.0.2-10/sysroots/x86_64-pokysdk-linux/usr/include/boost/asio/impl/io_context.hpp:190:5: error: static assertion failed: CompletionHandler type requirements not met^M
  190 |     BOOST_ASIO_LEGACY_COMPLETION_HANDLER_CHECK(^M
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^M

错误2-->

/volume/evo/files/opt/poky/3.0.2-10/sysroots/x86_64-pokysdk-linux/usr/include/c++/9.2.0/functional:443:8: error: no type named 'type' in 'class std::result_of<void (*&(LogSyslogHdr&, Ipc::Ipv4&, Layer4Bytes&, AftStatus (&)(Ipc::Istream<Ipc::ImMutable>&, const PacketService::AmPktIoHdr&)))(const LogSyslogHdr&, const Ipc::Ipv4&, const Layer4Bytes&, std::function<Status(Ipc::Istream<Ipc::ImMutable>&)>)>'^M
  443 |  using _Res_type_impl^M
      |        ^~~~~~~~~~~~~~^M

错误2重复了4次。我尝试使用 std::ref 传递参数,但我仍然面临同样的问题。 有人可以帮助我理解这里出了什么问题吗?

class LogSyslogTest{
 using LogSyslogCbFn = std::function<status(Ipc::Instream& stream)>;
static void v4Handler(const LogSyslogHdr& logSyslogHdr, const Ipc::Ipv4& ipv4,
                        const Layer4Bytes& l4Bytes, CbFn fn) {
        Ipc::Outstream out;
        out << logSyslogHdr;
        out << ipv4;
        out << l4Bytes.sPort;
        out << l4Bytes.dPort;
        Ipc::Instream in{out.data(), out.size()};
        fn(in);
}
}
//calling using gtest
Test F(LogSyslogTest, Ipv4Test) {
    LogSyslogHdr logSyslogHdr;
    getLogSyslogHdrIpv4(logSyslogHdr); //fills data

    Ipc::Ipv4 ipv4;
    getIpv4Hdr(ipv4);  //fills data

    Layer4Bytes l4Bytes;
    getL4Bytes1(l4Bytes);  //fills data

    for (int itr = 0; itr < 10000; ++itr) {
        ioService()->post(std::bind(LogSyslogTest::v4Handler, logSyslogHdr,
                                    ipv4, l4Bytes,Handler::processLog));
}

This is the abstract code snippet. When compiling this, i am getting following errors.
Error 1-->

/volume/evo/files/opt/poky/3.0.2-10/sysroots/x86_64-pokysdk-linux/usr/include/boost/asio/impl/io_context.hpp:190:5: error: static assertion failed: CompletionHandler type requirements not met^M
  190 |     BOOST_ASIO_LEGACY_COMPLETION_HANDLER_CHECK(^M
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^M

Error 2-->

/volume/evo/files/opt/poky/3.0.2-10/sysroots/x86_64-pokysdk-linux/usr/include/c++/9.2.0/functional:443:8: error: no type named 'type' in 'class std::result_of<void (*&(LogSyslogHdr&, Ipc::Ipv4&, Layer4Bytes&, AftStatus (&)(Ipc::Istream<Ipc::ImMutable>&, const PacketService::AmPktIoHdr&)))(const LogSyslogHdr&, const Ipc::Ipv4&, const Layer4Bytes&, std::function<Status(Ipc::Istream<Ipc::ImMutable>&)>)>'^M
  443 |  using _Res_type_impl^M
      |        ^~~~~~~~~~~~~~^M

Error 2 is repeated 4 times. I tried to pass the arguments using std::ref, still i am facing the same issue.
Can someone help me understand whats going wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

西瑶 2025-01-21 14:34:38

对于错误 1,请查看 Boost 1.74, io_context.hpp ,发现如下行:

// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a LegacyCompletionHandler.
BOOST_ASIO_LEGACY_COMPLETION_HANDLER_CHECK(
    LegacyCompletionHandler, handler) type_check;

Error 2指的是类型std::function&)> 但你有 std::function ;。我不知道流类型是否兼容,但 status 不是 Status

For Error 1, looking at Boost 1.74, io_context.hpp, one finds the following lines:

// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a LegacyCompletionHandler.
BOOST_ASIO_LEGACY_COMPLETION_HANDLER_CHECK(
    LegacyCompletionHandler, handler) type_check;

Error 2 refers to the type std::function<Status(Ipc::Istream<Ipc::ImMutable>&)> but you have std::function<status(Ipc::Instream& stream)>. Whether or not the stream types are compatible I don't know, but status is not Status.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文