boost::asio::connect compile failed [‘this’ pointer is null]

  asio, boost, c++

I tried to compile a project but it failed with the following error:

Build Error

Below is the code in my project:

boost::system::error_code ec;

auto endpoints = resolver->resolver().resolve(ip_address, std::to_string(port)), ec);

if (ec)

// Connect to server
boost::asio::ip::tcp::endpoint m_endpoint;
m_endpoint = *(boost::asio::connect(_socket, endpoints.begin(), endpoints.end(), ec));

The problem occurs in the call to boost::asio::connect function. By the way, I am using Boost C++ Libraries v1.77 and GCC 11.2.0.

How should I rectify this error? Thanks.

Source: Windows Questions C++