我正在尝试创建一个使用 Boost 套接字进行操作的类,以使连接易于使用。
我的SocketClient
班级有一些属性,boost::asio::ip::tcp::socket
其中之一。但是我的构造函数中出现C2512错误,因为boost::asio::ip::tcp::socket
它没有构造函数,所以不能存在。
在这里,查看类的代码:
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;
};
这是构造函数:
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
}
那么该怎么办?我必须保持sock
原样void*
吗?