I have a class used to wrap boost::asio and I use templates to define delegates:
template <class T>
struct Socket : public std::enable_shared_from_this<Socket<T>> {
explicit Socket<T>(T &delegate, const std::string &socket) : endpoint_{socket} {
socket_.reset(new asio::generic::stream_protocol::socket(service_));
socket_->connect(endpoint_, delegate_.error_code);
socket_->non_blocking(true);
}
void read() const noexcept {
std::vector<byte> bytes;
asio::async_read(*socket_, asio::buffer(bytes), asio::transfer_all(), delegate_.on_read);
}
virtual ~Socket<T>() noexcept = default;
private:
asio::io_service service_;
std::unique_ptr<asio::generic::stream_protocol::socket> socket_;
asio::local::stream_protocol::endpoint endpoint_;
T delegate_;
std::vector<byte> buffer_;
};
My problem is that passing the delegate method as a handler to asio::async_read results in the error
Reference to non-static member function must be called
What's the correct syntax to do this?
Aucun commentaire:
Enregistrer un commentaire