I am trying to make a class that manipulates with Boost sockets to make the conections simple to use.
My SocketClient
class has a few properties with boost::asio::ip::tcp::socket
being one of them. But I get C2512 error in my constructor, because boost::asio::ip::tcp::socket
cannot exist unitialised, as it has no constructor.
Here, see the code of the class:
class SocketClient {
private:
int port; //Port, currently unused
boost::asio::io_service io_service;
boost::asio::ip::tcp::resolver::iterator endpoint_iterator;
boost::asio::ip::tcp::socket sock; //This causes the error
//It wants to be like this (impossible too):
//boost::asio::ip::tcp::socket sock(io_service);
public:
void init(const char*, const char* );
SocketClient(); //Default constructor
bool connect();
bool read(int bytes, char *text);
bool send(int length, char *text);
bool send(std::string text);
unsigned int timeout;
};
And here is the constructor:
SocketClient::SocketClient() { //ERROR: (23): error C2512: 'boost::asio::basic_stream_socket<Protocol>' : no appropriate default constructor available
sock=boost::asio::ip::tcp::socket(io_service); //Adding this didn't help
}
So what to do? Do I have to keep sock
as void*
?