Template function parameter incomplete type c++

45 views Asked by At

I have a template function that I implement by passing as parameter another function cb.

Then I get the types of the arguments that I pass as parameters to the cb function.

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));
}

When I try to instantiate one of the two received_message_type or error_type, I get this error message:

error: incomplete type ‘received_message_type’ {aka ‘izycoinscppapi::exchanges::binance::ws::book_ticker_t’} used in nested name specifier received_message_type received_message = received_message_type::construct(json);

But for return_message_type, it works.

Here is the format of the cb function. I think it's because of the namespace on the receivedmsg and err parameters but I don't understand why.

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);
1

There are 1 answers

0
Samaritain Sim'S On

I found the reason for the problem. I had not imported the hpp containing the definition of received_message_type and error_type