I've encountered a problem when creating a client class for a program I'm doing.
I have the class defined in the header, like so:
class Client {
public:
Client();
private:
tcp::socket socket;
boost::asio::io_context io_context;
tcp::resolver resolver;
tcp::resolver::results_type endpoints;
};
However, when constructing the class, the program crashes with an error related to the socket initialization.
Here's the class constructor:
Client::Client() : resolver(io_context), endpoints(resolver.resolve("localhost", "daytime")), socket(io_context) { // Error here.
try {
boost::asio::connect(socket, endpoints);
}
catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
}
The call stack goes from the client class, to basic_socket and some other boost classes, until going to win_mutex, where the program finally crashes with an overflow error.
Is there something I'm doing wrong?