模板函数参数不完整类型 c++

Template function parameter incomplete type c++

提问人:Samaritain Sim'S 提问时间:12/5/2022 最后编辑:wohlstadSamaritain Sim'S 更新时间:12/5/2022 访问量:44

问:

我有一个模板函数,我通过将另一个函数 cb 作为参数传递来实现。

然后,我得到作为参数传递给 cb 函数的参数类型。

template<typename F>
websockets::handle start_subscription (std::string target, std::string payload, F cb) {
    using args_tuple = typename boost::callable_traits::args<F>::type;
    using received_message_type = typename std::tuple_element<3, args_tuple>::type;
    using return_message_type = typename std::tuple_element<4, args_tuple>::type;
    using error_type = typename std::tuple_element<5, args_tuple>::type;

    received_message_type received_message{};
    return_message_type return_message{};
    error_type eerror{};
}


websockets::handle websockets::binance_books(std::vector<std::string> pairs, binance_on_book_received_cb cb) {
    std::string target = binance_build_target(pairs, "bookTicker");
    std::string payload{""};
    return start_subscription(std::move(target), std::move(target), std::move(cb));
}

当我尝试实例化两个或之一时,我收到以下错误消息:received_message_typeerror_type

错误:不完整的类型“received_message_type”{又名“Izycoinscppapi::exchanges::Binance::WS::book_ticker_t'} 用于 嵌套名称说明符 received_message_type received_message = received_message_type::construct(json);

但是,它有效。return_message_type

这是 cb 函数的格式。我认为这是因为收到的msg和err参数上的命名空间,但我不明白为什么。

using binance_on_book_received_cb = std::function<bool(const char *fl, int ec, std::string errmsg, exchanges::binance::ws::book_ticker_t receivedmsg, fh_price_t returnmsg, exchanges::binance::errors::error_t err)>;
    handle binance_books(std::vector<std::string> pairs, binance_on_book_received_cb cb);
C 命名空间 g++ 类型名称 boost-tuples

评论

0赞 Xander 12/5/2022
stackoverflow.com/questions/44963201/......
1赞 Alan Birtles 12/5/2022
是完全定义的吗?请举一个最小的可重复的例子received_message_type

答:

0赞 Samaritain Sim'S 12/5/2022 #1

我找到了问题的原因。我没有导入包含 和 定义的 hppreceived_message_typeerror_type