我有一个模板函数,我通过传递另一个函数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_type
或error_type
中的一个时,我得到这个错误消息:
错误:不完整类型' received_message_type '{又名' izycoinscppapi::exchanges::binance::ws::book_ticker_t '}使用嵌套名称说明符received_message_type received_message =received_message_type:构造(json);
但对于return_message_type
,它有效。
下面是cb函数的格式。我认为这是因为名称空间上的receivedmsg和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);
我找到了问题的原因。我没有导入包含received_message_type
和error_type
定义的hpp